Page 1 of 1
Help in uploading a plugin
Posted: Fri Jan 25, 2013 11:11 am
by srikanth.kallu
1. I have written a simple shell script to find uptime
#!/bin/sh
uptime=$(uptime | awk ' { print $3 } ')
if (( "$uptime" >= 60 ))
then
echo "The server has not been patched or rebooted for 60 or more days"
stateid=2
elif (( "$uptime" >= 30 ))
then
echo "The server has not been patched or rebooted for 30 or more days"
stateid=1
else
echo "system state is OK"
stateid=0
fi
exit $stateid
Now this works fine in the command line, in the process of making it a plugin.
I did
Re: Help in uploading a plugin
Posted: Fri Jan 25, 2013 11:45 am
by sreinhardt
Just to be sure, can you check that the script has execute permissions set, as well as the name is the same on the check command definition as it is in the filesystem? Permissions could also be causing some issue in this case. The 127 error indicates that it cannot be found, is not executable, or that nagios does not have permission to access it. One other suggestion, completely unrelated to errors, instead of setting a variable then exiting with it, you could just directly exit at the end of your if sequence. I also added a case for if it is unable to match any of your checks.
Code: Select all
#!/bin/sh
uptime=$(uptime | awk ' { print $3 } ')
if (( "$uptime" >= 60 ))
then
echo "The server has not been patched or rebooted for 60 or more days"
exit 2
elif (( "$uptime" >= 30 ))
then
echo "The server has not been patched or rebooted for 30 or more days"
exit 1
else
echo "system state is OK"
exit 0
fi
# only happens if not matching any other check
echo "The server uptime is unknown"
exit 3
Re: Help in uploading a plugin
Posted: Fri Jan 25, 2013 11:46 am
by lmiltchev
In the command definition, you should have:
Code: Select all
$USER1$/check_uptime -H $HOSTADDRESS$ $ARG1$
Hope this helps.
Re: Help in uploading a plugin
Posted: Fri Jan 25, 2013 12:20 pm
by srikanth.kallu
I have check the execute permissons
[root@nagiosxi libexec]# ls -ltr check_uptime
-rwxr-xr-x 1 root root 328 Jan 25 11:06 check_uptime
My command line has the same name as in the file system.
$USER1$/check_uptime -H $HOSTADDRESS$ $ARG1$ ( i added -H $HOSTADDRESS$)
now i got this alert
Nagios has detected a problem with this service.
Notification Type: PROBLEM
Service: uptime
Host: b3sl02
Address: 192.168.0.190
State: UNKNOWN
Info:
system state is OK
Date/Time: 2013-01-25 11:08:50
In the above alert it still shows system state is ok but that partcular host is not rebooted since 58 days. I am expecting it to give me a warning alert as per my script.
I am not sure what i am missing.
Re: Help in uploading a plugin
Posted: Fri Jan 25, 2013 1:57 pm
by slansing
What are you getting when you run your script remotely from the Nagios shell and not the web UI, I'm not sure that you have the logic set up correctly for the return codes. Keep in mind you will need to run the script through an agent.
Re: Help in uploading a plugin
Posted: Fri Jan 25, 2013 4:06 pm
by scottwilkerson
You will want to copy the script to your remote machine and execute them via NRPE. For example, place the check_uptime in the /usr/local/nagios/libexec directory on the REMOTE machine. Then add the following line to your nrpe.cfg on the remote machine
Code: Select all
command[check_uptime]=/usr/local/nagios/libexec/check_uptime
Lets remember to make the file executable
Code: Select all
chmod +x /usr/local/nagios/libexec/check_uptime
And restart NRPE (this may vary by OS)
Now, on the Nagios XI server, create a new service (or run the NRPE wizard)
To do manually, you can create a service in the CCM, add your hosts and any templates you would like.
Select check_nrpe for the command
Set