Page 1 of 1

Monitor Cluster shared volumes

Posted: Tue Jun 14, 2016 11:03 am
by partnernet
Hello,

I have an already set-up Nagios Core that uses this script in order to monitor some Hyper-v Cluster shared volumes
https://exchange.nagios.org/directory/P ... 1442825460

I noticed though that the code is a little bit changed and the warning and critical values are static inside the code and not passing through as an argument:

Code: Select all

Param(
    [parameter(Mandatory=$true)]
    [alias("n")]
    $csvname)  
    #[parameter(Mandatory=$true)]
    #[alias("w")]
    #$warnlevel,
    #[parameter(Mandatory=$true)]
    #[alias("c")]
    #$critlevel)

#$csvname="Cluster Storage 4"
$warnlevel=80
$critlevel=90
So I tried to change that and uncomented the above lines in order to pass them through from my nagios service definition.

Here is my service definition:

Code: Select all

define service
{use generic-service,graphed-service
service_description Cluster: Volume 3 free disk space
check_command check_hyperv_csv_freespaceTest!Cluster Storage 4!90!95}
Command Definition:

Code: Select all

define command { 
command_name check_hyperv_csv_freespaceTest 
command_line /usr/local/nagios/libexec/check_nrpe -H $HOSTADDRESS$ -c check_hyperv_csv_freespace -a "$ARG1$" "$ARG2$" "$ARG3$"
} 
and nscient.ini

Code: Select all

check_hyperv_csv_freespace=cmd /c echo scripts\mine.ps1 -n "$ARG1$" -w "$ARG2$" -c "$ARG3$"; exit($lastexitcode) | powershell.exe -command -
and Nagios returns this:

Code: Select all

Status Information:	scriptsmine.ps1 -n ARG1$ -w "90 -c "95": exit($lastexitcode)
Performance Data:	'powershell.exe'=0 '-command'=0 '-'=0
I have tried many different ways to pass my arguments (with and without quotes, with and without spaces...)and all result in some kind of Argument passing error.
Any help would be greatly apreciated.
Thanks
Anna

Re: Monitor Cluster shared volumes

Posted: Tue Jun 14, 2016 5:01 pm
by lmiltchev
Does it help if you remove the double quotes around your args?

Code: Select all

define command {
command_name check_hyperv_csv_freespaceTest
command_line /usr/local/nagios/libexec/check_nrpe -H $HOSTADDRESS$ -c check_hyperv_csv_freespace -a $ARG1$ $ARG2$ $ARG3$
} 

Re: Monitor Cluster shared volumes

Posted: Tue Jun 14, 2016 7:52 pm
by Box293
partnernet wrote:I have tried many different ways to pass my arguments (with and without quotes, with and without spaces...)and all result in some kind of Argument passing error.
Can you show us the command you execute at the CLI along with the output produced.

I want to see it working first, it'll help make sure we create the correct configs.

Re: Monitor Cluster shared volumes

Posted: Wed Jun 15, 2016 3:55 am
by partnernet
So I figured out one of the problems.
My Volume name had spaces in it so this could not pass as an argument, so I modified my script like this:

Code: Select all

$csvname = $csvname.replace('+' , ' ')
and I am running the below from the CLI:

Code: Select all

.\mine.ps1 -n Cluster+Storage+4 -w 90 -c 95
and correctly I get:

Code: Select all

OK - Cluster Storage 4 total: $1092GB, used: $886GB (81%), free: 206GB (18%) | 'Cluster Storage 4 used_space'=886Gb;982;1037;0;1092
When I try to run it from nagios I get the following:

Code: Select all

Status Information:	scriptsmine.ps1 -n ARG1$ -w "$ARG2$ -c "$ARG3$": exit($lastexitcode)
Performance Data:	'powershell.exe'=0 '-command'=0 '-'=0
I can't figure out this weird output, its like some quotes are not being recognized. I tried typing the lines about arguments all over again in case it was some character issue, but no luck.
I have restarted both nagios and nsclient service.

Removing the quotes doesn't have a difference(which I guess is weird).

Thanks.
Anna

Re: Monitor Cluster shared volumes

Posted: Wed Jun 15, 2016 5:36 am
by partnernet
Hooray!!

I figured it out at last...

So this is how it worked for me:

Command definition:

Code: Select all

define command { 
command_name check_hyperv_csv_freespace 
command_line /usr/local/nagios/libexec/check_nrpe -H $HOSTADDRESS$ -c check_hyperv_csv_freespace -a $ARG1$
} 
I am not sure why the double quotes are wrong, all my other command definition are using quotes :?

Service definition:

Code: Select all

define service{
use generic-service,graphed-service
hostgroup_name  host2012
service_description Cluster: Volume 3 free disk space
check_command check_hyperv_csv_freespace!Cluster+Storage+4 90 95
}
Pass the Volume name with + instead of spaces and replace it back again in the script

nsclient.ini

Code: Select all

check_hyperv_csv_freespace=cmd /c echo scripts\mine.ps1 -n $ARG1$ -w $ARG2$ -c $ARG3$; exit($lastexitcode) | powershell.exe -command -
without quotes again...

Thanks guys for your assistance!
Anna

Re: Monitor Cluster shared volumes

Posted: Wed Jun 15, 2016 9:51 am
by mcapra
Glad you were able to find a solution! Is it alright if we lock this thread and mark the issue as resolved?