Page 1 of 1

Need help with service description

Posted: Wed Apr 12, 2017 7:50 pm
by jim
Hello Guys,

I have currently the following two service defined as below:

Code: Select all

define service {
        use                             my-webapp-service
        hostgroup_name                  all
        service_description             System check - PING
        check_command                   check_ping!100.0,20%!500.0,60%
        }

Code: Select all

define service {
        use                             my-webapp-service
        hostgroup_name                  all
        service_description             System check - Swap Usage
        check_command                   check_nrpe!check_swap
        check_interval                  1
        }
What I want is output string to be:
System check - PING - <Actual hostname where this alarm got fired off>
System check - Swap Usage - <Actual hostname where this alarm got fired off >

I think this could be possible but I just don't know how to make it possible.

Would sincerely appreciate your guidance on that.

Many Thanks
Jim

Re: Need help with service description

Posted: Thu Apr 13, 2017 1:19 pm
by mcapra
Here's all the Nagios system macros:
https://assets.nagios.com/downloads/nag ... olist.html

$HOSTNAME$ does what you want, but unfortunately you're not able to use any of the macros in the service_description value. The closest you could get would be to use $HOSTNAME$ in the event/notification handler's execution.

Re: Need help with service description

Posted: Sat Apr 15, 2017 9:32 am
by jim
That is looking pretty awful for a open source monitoring solution like Nagios.

Anyway, I am trying to create a simple plugin for nagios. First step is to make it work, second step is to add "echo $hostname" in it so I get information of hostname.

Nagios Server:
/etc/nagios/objects/command.cfg

Code: Select all

define command{
        command_name    check_loadavg
        command_line    $USER1$/check_nrpe -H $HOSTADDRESS$ -c check_loadavg
        }
/usr/lib64/nagios/plugins/check_nrpe -H 192.168.1.11 -c check_loadavg
NRPE: Command 'check_loadavg' not defined
cat /usr/lib64/nagios/plugins/check_loadavg
#!/bin/bash

loadavg=$( uptime | awk -F: '{print $5}' | xargs )

load1int=$( echo $loadavg | cut -d "." -f 1 )
load5int=$( echo $loadavg | awk -F, '{print $2}' | xargs | cut -d "." -f 1 )
load15int=$( echo $loadavg | awk -F, '{print $3}' | xargs | cut -d "." -f 1 )

load1=$( echo $loadavg | awk -F, '{print $1}' )
load5=$( echo $loadavg | awk -F, '{print $2}' )
load15=$( echo $loadavg | awk -F, '{print $3}' )

output="Load Average: $loadavg | Load_1min=$load1, Load_5min=$load5, Load_15min=$load15"

if [ $load1int -le 1 -a $load5int -le 1 -a $load15int -le 1 ]
then
    echo "OK- $output"
    exit 0
elif [ $load1int -le 2 -a $load5int -le 2 -a $load15int -le 2 ]
then
    echo "WARNING- $output"
    exit 1
elif [ $load1int -gt 2 -a $load5int -gt 2 -a $load15int -gt 2 ]
then
    echo "CRITICAL- $output"
    exit 2
else
echo "UNKNOWN- $output"
exit 3
fi
If I execute one of the in-built nagios scripts I have to provide parameters
/usr/lib64/nagios/plugins/check_load
check_load: Could not parse arguments
Usage:
check_load [-r] -w WLOAD1,WLOAD5,WLOAD15 -c CLOAD1,CLOAD5,CLOAD15

For check_loadavg, I don't have to provide any parameters.

/usr/lib64/nagios/plugins/check_loadavg
OK- Load Average: 0.41, 0.47, 0.54 | Load_1min=0.41, Load_5min= 0.47, Load_15min= 0.54

Permissions on files.

Code: Select all

ls -l /usr/lib64/nagios/plugins/check_loadavg
-rwxr-xr-x. 1 root root 861 Apr 15 00:40 /usr/lib64/nagios/plugins/check_loadavg

ls -l /usr/lib64/nagios/plugins/check_load
-rwxr-xr-x. 1 root root 49312 Sep 12  2015 /usr/lib64/nagios/plugins/check_load

At client machine, where nrpe is running:
File:
/etc/nagios/nrpe.cfg

Code: Select all

command[check_loadavg]=/usr/lib64/nagios/plugins/check_loadavg
/usr/lib64/nagios/plugins/check_loadavg
#!/bin/bash

loadavg=$( uptime | awk -F: '{print $5}' | xargs )

load1int=$( echo $loadavg | cut -d "." -f 1 )
load5int=$( echo $loadavg | awk -F, '{print $2}' | xargs | cut -d "." -f 1 )
load15int=$( echo $loadavg | awk -F, '{print $3}' | xargs | cut -d "." -f 1 )

load1=$( echo $loadavg | awk -F, '{print $1}' )
load5=$( echo $loadavg | awk -F, '{print $2}' )
load15=$( echo $loadavg | awk -F, '{print $3}' )

output="Load Average: $loadavg | Load_1min=$load1, Load_5min=$load5, Load_15min=$load15"

if [ $load1int -le 1 -a $load5int -le 1 -a $load15int -le 1 ]
then
    echo "OK- $output"
    exit 0
elif [ $load1int -le 2 -a $load5int -le 2 -a $load15int -le 2 ]
then
    echo "WARNING- $output"
    exit 1
elif [ $load1int -gt 2 -a $load5int -gt 2 -a $load15int -gt 2 ]
then
    echo "CRITICAL- $output"
    exit 2
else
echo "UNKNOWN- $output"
exit 3
fi
Restarted nagios server but still no charm.

I have no idea where I am going wrong!

Please assist. Thanks.

Re: Need help with service description

Posted: Sun Apr 16, 2017 8:30 pm
by tacolover101
jim wrote:That is looking pretty awful for a open source monitoring solution like Nagios.

Anyway, I am trying to create a simple plugin for nagios. First step is to make it work, second step is to add "echo $hostname" in it so I get information of hostname.

Nagios Server:
/etc/nagios/objects/command.cfg

Code: Select all

define command{
        command_name    check_loadavg
        command_line    $USER1$/check_nrpe -H $HOSTADDRESS$ -c check_loadavg
        }
/usr/lib64/nagios/plugins/check_nrpe -H 192.168.1.11 -c check_loadavg
NRPE: Command 'check_loadavg' not defined
cat /usr/lib64/nagios/plugins/check_loadavg
#!/bin/bash

loadavg=$( uptime | awk -F: '{print $5}' | xargs )

load1int=$( echo $loadavg | cut -d "." -f 1 )
load5int=$( echo $loadavg | awk -F, '{print $2}' | xargs | cut -d "." -f 1 )
load15int=$( echo $loadavg | awk -F, '{print $3}' | xargs | cut -d "." -f 1 )

load1=$( echo $loadavg | awk -F, '{print $1}' )
load5=$( echo $loadavg | awk -F, '{print $2}' )
load15=$( echo $loadavg | awk -F, '{print $3}' )

output="Load Average: $loadavg | Load_1min=$load1, Load_5min=$load5, Load_15min=$load15"

if [ $load1int -le 1 -a $load5int -le 1 -a $load15int -le 1 ]
then
    echo "OK- $output"
    exit 0
elif [ $load1int -le 2 -a $load5int -le 2 -a $load15int -le 2 ]
then
    echo "WARNING- $output"
    exit 1
elif [ $load1int -gt 2 -a $load5int -gt 2 -a $load15int -gt 2 ]
then
    echo "CRITICAL- $output"
    exit 2
else
echo "UNKNOWN- $output"
exit 3
fi
If I execute one of the in-built nagios scripts I have to provide parameters
/usr/lib64/nagios/plugins/check_load
check_load: Could not parse arguments
Usage:
check_load [-r] -w WLOAD1,WLOAD5,WLOAD15 -c CLOAD1,CLOAD5,CLOAD15

For check_loadavg, I don't have to provide any parameters.

/usr/lib64/nagios/plugins/check_loadavg
OK- Load Average: 0.41, 0.47, 0.54 | Load_1min=0.41, Load_5min= 0.47, Load_15min= 0.54

Permissions on files.

Code: Select all

ls -l /usr/lib64/nagios/plugins/check_loadavg
-rwxr-xr-x. 1 root root 861 Apr 15 00:40 /usr/lib64/nagios/plugins/check_loadavg

ls -l /usr/lib64/nagios/plugins/check_load
-rwxr-xr-x. 1 root root 49312 Sep 12  2015 /usr/lib64/nagios/plugins/check_load

At client machine, where nrpe is running:
File:
/etc/nagios/nrpe.cfg

Code: Select all

command[check_loadavg]=/usr/lib64/nagios/plugins/check_loadavg
/usr/lib64/nagios/plugins/check_loadavg
#!/bin/bash

loadavg=$( uptime | awk -F: '{print $5}' | xargs )

load1int=$( echo $loadavg | cut -d "." -f 1 )
load5int=$( echo $loadavg | awk -F, '{print $2}' | xargs | cut -d "." -f 1 )
load15int=$( echo $loadavg | awk -F, '{print $3}' | xargs | cut -d "." -f 1 )

load1=$( echo $loadavg | awk -F, '{print $1}' )
load5=$( echo $loadavg | awk -F, '{print $2}' )
load15=$( echo $loadavg | awk -F, '{print $3}' )

output="Load Average: $loadavg | Load_1min=$load1, Load_5min=$load5, Load_15min=$load15"

if [ $load1int -le 1 -a $load5int -le 1 -a $load15int -le 1 ]
then
    echo "OK- $output"
    exit 0
elif [ $load1int -le 2 -a $load5int -le 2 -a $load15int -le 2 ]
then
    echo "WARNING- $output"
    exit 1
elif [ $load1int -gt 2 -a $load5int -gt 2 -a $load15int -gt 2 ]
then
    echo "CRITICAL- $output"
    exit 2
else
echo "UNKNOWN- $output"
exit 3
fi
Restarted nagios server but still no charm.

I have no idea where I am going wrong!

Please assist. Thanks.
nagios is open source which is the beautiful part about it. perhaps the idea hasn't been thought about before? no need to attack people for making oepn source software. you could file a feature request over here - https://github.com/NagiosEnterprises/nagioscore/issues - the developers are pretty active i think.

i don't know what exactly your asking in the remainder of your post, but i do see this - NRPE: Command 'check_loadavg' not defined.

the reason for it probably is because check_loadavg is NOT defined in your nrpe.cfg on the CLIENT side. i'm not sure if your paste is entirely your nrpe.cfg or if you meant to seperate them out, but if you have command[check_loadavg]=/usr/lib64/nagios/plugins/check_loadavg then you should be good to go. you'll need to restart the nrpe or xinetd service for changes to take effect.

Re: Need help with service description

Posted: Mon Apr 17, 2017 9:36 am
by jim
My sincerest apologies, I had no intention to offend anyone. Having an hostname would be definitely be helpful and I just thought why we are missing this basic functionality. Thank you for sharing the link, I have raised it as new issue. Let us hope for the best.

On another note, what I am asking is I am trying to create a very basic level plugin as a workaround. I intend to use variable "$hostname" in it but for some reason the plugin is not working.
After your suggestion I did restart NRPE service on client machine and it is better than before but again not an ideal output. It now says Unable to read output.

Code: Select all

/usr/lib64/nagios/plugins/check_nrpe -H 192.168.1.11 -c check_loadavg
NRPE: Unable to read output
/usr/lib64/nagios/plugins/check_nrpe -H 192.168.1.11
NRPE v2.15
What could be the reason ?

Re: Need help with service description

Posted: Mon Apr 17, 2017 9:52 am
by jfrickson
jim wrote:After your suggestion I did restart NRPE service on client machine and it is better than before but again not an ideal output. It now says Unable to read output.

Code: Select all

/usr/lib64/nagios/plugins/check_nrpe -H 192.168.1.11 -c check_loadavg
NRPE: Unable to read output
/usr/lib64/nagios/plugins/check_nrpe -H 192.168.1.11
NRPE v2.15
What could be the reason ?
Check the syslog messages on both the Nagios machine and the remote. One or both should have some information about what the problem is.

Re: Need help with service description

Posted: Mon Apr 24, 2017 11:23 am
by jfrickson
jim,

I wrote the following very basic check:

Code: Select all

---------------------- Service Description ----------------------
define service{
    use                     local-service
    host_name               host1
    service_description     My test check
    check_command           check_test
    max_check_attempts      2
}


---------------------- check_test Script ----------------------
#!/bin/bash
echo "Host name is '$NAGIOS_HOSTNAME' Service name is '$NAGIOS_SERVICEDESC'"
exit 0


---------------------- Status Output ----------------------
Host name is 'host1' Service name is 'My test check'
So, if I'm not mistaken, using the NAGIOS_HOSTNAME environment variable should do what you need.

Re: Need help with service description

Posted: Mon Jul 03, 2017 8:16 am
by jim
I got your concept, but I think it is difficult to implement. The reason I say so is because this check_users or for that matter check_* is the script which I think/believe is shipped out by nagios core as out of box solution. So how do I change it its string ?

Re: Need help with service description

Posted: Wed Jul 05, 2017 12:31 pm
by lmiltchev
I got your concept, but I think it is difficult to implement. The reason I say so is because this check_users or for that matter check_* is the script which I think/believe is shipped out by nagios core as out of box solution. So how do I change it its string ?
Can you elaborate on this? Why do you need to change the plugins that ship with Nagios Core by default? I thought you were developing your own, custom plugin... Did you check the syslog messages on both the Nagios machine and the remote as suggested by jfrickson?