New Script to check jobs returning Blank from Nagios Check

Support forum for Nagios Core, Nagios Plugins, NCPA, NRPE, NSCA, NDOUtils and more. Engage with the community of users including those using the open source solutions.
Locked
kwhogster
Posts: 644
Joined: Wed Oct 14, 2015 6:51 pm
Location: Wood Ridge NJ USA
Contact:

New Script to check jobs returning Blank from Nagios Check

Post by kwhogster »

Trying to write a script so that Nagios can check My Veeam Backup Copy Jobs

My command line

Code: Select all

/usr/lib/nagios/plugins/check_nrpe -t 50 -H TGCS008 -c  checkveeamcopy -a 'Exchange Backup Copy Job'
My Nsclient.ini

Code: Select all

; check veeam copy jobs
checkveeamcopy = cmd /c echo scripts/powershell/check_veeam_backups.ps1 "$ARG1$" "$ARG2$"; exit $LastExitCode | powershell.exe -command -

When I run it from my command line on the Nagios server I get a blank return.

root@nagios017:/usr/local/nagios/etc/objects/windowsservers# /usr/lib/nagios/plugins/check_nrpe -t 50 -H TGCS008 -c checkveeamcopy -a 'Exchange Backup Copy Job'


root@nagios017:/usr/local/nagios/etc/objects/windowsservers#


My powershell script

Code: Select all

$name = $args[0]

if ((Get-PSSnapin -Name VeeamPSSNapin -ErrorAction SilentlyContinue) -eq $null)

{

    Add-PSSnapin VeeamPSSNapin

}

$JobNames = Get-VBRJob -Name $name


    foreach ($JobName in $JobNames) {

    $Job = Get-VBRJob -name $JobName.Name

    $LastSession = $Job.FindLastSession()

    $Name = $Job.Name

    $Status = $LastSession.State

    $Progress = "$($LastSession.BaseProgress)%"

    $results += New-Object PSObject -Property @{JobName = $Name; Status = $Status; Progress = $Progress;}
    $results
    
} 
When I run the powerhell script manually

PS C:\program files\nsclient++\scripts\powershell> .\check_veeam_backups.ps1 'Exchange Backup Copy Job'

Status Progress JobName
------ -------- -------
Idle 100% Exchange Backup Copy Job


Any ideas


Thank you

Tom
User avatar
cdienger
Support Tech
Posts: 5045
Joined: Tue Feb 07, 2017 11:26 am

Re: New Script to check jobs returning Blank from Nagios Che

Post by cdienger »

Try moving $results outside of the foreach loop and adding an exit code:

Code: Select all

    $name = $args[0]

    if ((Get-PSSnapin -Name VeeamPSSNapin -ErrorAction SilentlyContinue) -eq $null)

    {

        Add-PSSnapin VeeamPSSNapin

    }

	$results = ""
    $JobNames = Get-VBRJob -Name $name


        foreach ($JobName in $JobNames) {

        $Job = Get-VBRJob -name $JobName.Name

        $LastSession = $Job.FindLastSession()

        $Name = $Job.Name

        $Status = $LastSession.State

        $Progress = "$($LastSession.BaseProgress)%"

        $results += New-Object PSObject -Property @{JobName = $Name; Status = $Status; Progress = $Progress;}
       
    } 
	
	$results
	exit 0
As of May 25th, 2018, all communications with Nagios Enterprises and its employees are covered under our new Privacy Policy.
kwhogster
Posts: 644
Joined: Wed Oct 14, 2015 6:51 pm
Location: Wood Ridge NJ USA
Contact:

Re: New Script to check jobs returning Blank from Nagios Che

Post by kwhogster »

Code: Select all

$name = $args[0]

if ((Get-PSSnapin -Name VeeamPSSNapin -ErrorAction SilentlyContinue) -eq $null)

{

    Add-PSSnapin VeeamPSSNapin

}

$JobNames = Get-VBRJob -Name $name


    foreach ($JobName in $JobNames) {

    $Job = Get-VBRJob -name $JobName.Name

    $LastSession = $Job.FindLastSession()

    $Name = $Job.Name

    $Status = $LastSession.State

    $Progress = "$($LastSession.BaseProgress)%"

    $results += New-Object PSObject -Property @{JobName = $Name; Status = $Status; Progress = $Progress;}
    
    
} 

$results
exit 0

Same results from the Nagios server command line just returns blanks
From powershell works fine.
User avatar
cdienger
Support Tech
Posts: 5045
Joined: Tue Feb 07, 2017 11:26 am

Re: New Script to check jobs returning Blank from Nagios Che

Post by cdienger »

The line:

Code: Select all

$results = ""
is missing in your updated script. Make sure it is added outside of and above the scope of the foreach loop.
As of May 25th, 2018, all communications with Nagios Enterprises and its employees are covered under our new Privacy Policy.
kwhogster
Posts: 644
Joined: Wed Oct 14, 2015 6:51 pm
Location: Wood Ridge NJ USA
Contact:

Re: New Script to check jobs returning Blank from Nagios Che

Post by kwhogster »

root@tgcs017:/usr/local/nagios/etc/objects/windowsservers# /usr/lib/nagios/plugi
No output available from command (checkveeamcopy).


Now I get this
User avatar
tgriep
Madmin
Posts: 9177
Joined: Thu Oct 30, 2014 9:02 am

Re: New Script to check jobs returning Blank from Nagios Che

Post by tgriep »

I just want to verify that if you run the script manually, is the first line a blank line?

If so, then the powershell script needs to be written to not do that as the first line is sent back to Nagios as a blank, it will show as a blank line in the GUI.
Be sure to check out our Knowledgebase for helpful articles and solutions!
kwhogster
Posts: 644
Joined: Wed Oct 14, 2015 6:51 pm
Location: Wood Ridge NJ USA
Contact:

Re: New Script to check jobs returning Blank from Nagios Che

Post by kwhogster »

Guys I got this working now.

changed the "$results = """ to this write-host $Name $Status $Progress $LastResult

I would like to post this script so that other can use this as a plugin.

Can you tell me how I can do that?

Thank you

Tom
User avatar
tgriep
Madmin
Posts: 9177
Joined: Thu Oct 30, 2014 9:02 am

Re: New Script to check jobs returning Blank from Nagios Che

Post by tgriep »

The Nagios Exchange site is where you would post the Powershell script.
https://exchange.nagios.org/

Create a login, upload and document the plugin and after it is reviewed, it should be enabled for others to download.
Be sure to check out our Knowledgebase for helpful articles and solutions!
kwhogster
Posts: 644
Joined: Wed Oct 14, 2015 6:51 pm
Location: Wood Ridge NJ USA
Contact:

Re: New Script to check jobs returning Blank from Nagios Che

Post by kwhogster »

Thank you

I will document it and post

You can lock this one as resolved.

Thanks

Tom
User avatar
tgriep
Madmin
Posts: 9177
Joined: Thu Oct 30, 2014 9:02 am

Re: New Script to check jobs returning Blank from Nagios Che

Post by tgriep »

Your Welcome.

Closing the post.
Be sure to check out our Knowledgebase for helpful articles and solutions!
Locked