Page 2 of 3

Re: Check_reg_key.vbs "folder not found"

Posted: Tue Jul 10, 2018 3:39 pm
by lpereira
scottwilkerson wrote:
lpereira wrote:Does this script work? or should i need to find a different one.
as I had stated, we are not familiar with the plugin, you need to test it to see if it works from the Windows command line, if you cannot successfully do that, I would try something different.
I did, i run the script from windows CMD, and i added the screenshot on my previous posts.

Re: Check_reg_key.vbs "folder not found"

Posted: Tue Jul 10, 2018 3:47 pm
by scottwilkerson
lpereira wrote:I did, i run the script from windows CMD, and i added the screenshot on my previous posts.
It needs to run SUCCESSFULLY, the screenshots are errors

Re: Check_reg_key.vbs "folder not found"

Posted: Tue Jul 10, 2018 3:57 pm
by lpereira
scottwilkerson wrote:
lpereira wrote:I did, i run the script from windows CMD, and i added the screenshot on my previous posts.
It needs to run SUCCESSFULLY, the screenshots are errors
That's why i opened this post, i'm not able to get it working properly.

anyway... did you know any other scritp that might do what i need? (checking the REG_SZ value for changes)

thanks.

Re: Check_reg_key.vbs "folder not found"

Posted: Tue Jul 10, 2018 4:09 pm
by scottwilkerson
I don't know of one that does what you describe, but there is a post showing what could be put in a batch file to get some return
https://support.nagios.com/forum/viewto ... 35#p172512

This could be parsed and turned into a plugin if you added some logic.

Re: Check_reg_key.vbs "folder not found"

Posted: Thu Jul 12, 2018 3:35 pm
by lpereira
scottwilkerson wrote:I don't know of one that does what you describe, but there is a post showing what could be put in a batch file to get some return
https://support.nagios.com/forum/viewto ... 35#p172512

This could be parsed and turned into a plugin if you added some logic.
I Finally asked a partner to create a PS1 for this. This Scritp, check diferences between 3 registry keys with 3 different plain texts, if the registry is different then will notify.

this is the output for check with errors (each no error represents a folder, file, and extension):

Code: Select all

PS C:\Program Files\NSClient++\scripts> C:\Program Files\NSClient++\scripts\Check_reg.ps1
NO ERROR
NO ERROR
Registry File Modified
1 exit 1
This is the output when there are no differences:

Code: Select all

 PS C:\Program Files\NSClient++\scripts> C:\Program Files\NSClient++\scripts\Check_reg.ps1
NO ERROR
NO ERROR
NO ERROR
0 exit 0
From nagios Side i was able to add the command, and from GUI check results ok. However i'm having issues trying to parsing the exits in order to generate the "Critical" one.

Re: Check_reg_key.vbs "folder not found"

Posted: Fri Jul 13, 2018 9:50 am
by tmcdonald
Can you talk to your partner again? This is a bit out of scope of what we can support since it is a custom plugin that sounds like it needs modification. Our plugin guidelines should help with that.

Re: Check_reg_key.vbs "folder not found"

Posted: Fri Jul 13, 2018 1:20 pm
by lpereira
tmcdonald wrote:Can you talk to your partner again? This is a bit out of scope of what we can support since it is a custom plugin that sounds like it needs modification. Our plugin guidelines should help with that.

i Have made a modification on the script. Now it only returns a 0 when the records are equal, and 2 when there is a modification.
3.jpg
i have added con CCM the options "-a 0" IN $ARG1$ and 2 in $ARG2$ (as you can see on the images below).
1.jpg
however i'm still having a "service ok" even if the output is 2.
2.jpg
Please i need to know how to parse the outputs correctly on CCM

Thanks!

Re: Check_reg_key.vbs "folder not found"

Posted: Fri Jul 13, 2018 2:17 pm
by jomann
As @tmcdonald pointed out, we can't do custom plugins, it's out of the scope of support.

I can explain briefly what I think your issue is. The output you see in the interface comes from whatever your plugin returns to the screen - in your example it was a 0 or a 2. The actual status of the plugin (OK, WARNING, CRITICAL) is based on the exit code of the plugin. This is why you're getting a 2 as the output and OK as the status.

Re: Check_reg_key.vbs "folder not found"

Posted: Fri Jul 13, 2018 2:45 pm
by lmiltchev
I will give you a very simple example of a PS script that returns 0 or 2 exit codes (OK or CRITICAL).

example.ps1

Code: Select all

$LastExitCode = 0
$output = ""
$crit = (Get-Date).AddDays(-1).toString("yyyy-M-dd")

$MyTimeStamp = Get-Item c:\TEMP\test1.txt | Foreach {$_.LastWriteTime}
$MyTimeStamp = $MyTimeStamp.toString("yyyy-M-dd")

$Message = "The timestamp on my file is: $MyTimeStamp"

if ($MyTimeStamp -lt $crit)
    {
        $LastExitCode = 2
        echo "Critical: $Message"
        exit 2
    } else {
        $LastExitCode = 0
        echo "OK: $Message"
        exit 0
    }
In the nsclient.ini

Code: Select all

check_timestamp = cmd /c echo scripts\example.ps1; exit $LastExitCode | powershell.exe -command -
Testing from the CLI on the Nagios XI server:
1. Checking a file older than one day.
example01.PNG

Code: Select all

/usr/local/nagios/libexec/check_nrpe -H x.x.x.x -c check_timestamp
Critical: The timestamp on my file is: 2018-4-27
echo $?
2
2. Checking the updated file (newer than one day).
example02.PNG

Code: Select all

/usr/local/nagios/libexec/check_nrpe -H x.x.x.x -c check_timestamp
OK: The timestamp on my file is: 2018-7-13
echo $?
0
Hope this helps.

Re: Check_reg_key.vbs "folder not found"

Posted: Fri Jul 13, 2018 3:17 pm
by lpereira
lmiltchev wrote:I will give you a very simple example of a PS script that returns 0 or 2 exit codes (OK or CRITICAL).

example.ps1

Code: Select all

$LastExitCode = 0
$output = ""
$crit = (Get-Date).AddDays(-1).toString("yyyy-M-dd")

$MyTimeStamp = Get-Item c:\TEMP\test1.txt | Foreach {$_.LastWriteTime}
$MyTimeStamp = $MyTimeStamp.toString("yyyy-M-dd")

$Message = "The timestamp on my file is: $MyTimeStamp"

if ($MyTimeStamp -lt $crit)
    {
        $LastExitCode = 2
        echo "Critical: $Message"
        exit 2
    } else {
        $LastExitCode = 0
        echo "OK: $Message"
        exit 0
    }
In the nsclient.ini

Code: Select all

check_timestamp = cmd /c echo scripts\example.ps1; exit $LastExitCode | powershell.exe -command -
Testing from the CLI on the Nagios XI server:
1. Checking a file older than one day.
example01.PNG

Code: Select all

/usr/local/nagios/libexec/check_nrpe -H x.x.x.x -c check_timestamp
Critical: The timestamp on my file is: 2018-4-27
echo $?
2
2. Checking the updated file (newer than one day).
example02.PNG

Code: Select all

/usr/local/nagios/libexec/check_nrpe -H x.x.x.x -c check_timestamp
OK: The timestamp on my file is: 2018-7-13
echo $?
0
Hope this helps.
THANKS!!! that did the job

Thank you!