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
Help in uploading a plugin
-
srikanth.kallu
- Posts: 243
- Joined: Thu Jul 26, 2012 10:48 am
Help in uploading a plugin
You do not have the required permissions to view the files attached to this post.
-
sreinhardt
- -fno-stack-protector
- Posts: 4366
- Joined: Mon Nov 19, 2012 12:10 pm
Re: Help in uploading a plugin
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
Nagios-Plugins maintainer exclusively, unless you have other C language bugs with open-source nagios projects, then I am happy to help! Please pm or use other communication to alert me to issues as I no longer track the forum.
Re: Help in uploading a plugin
In the command definition, you should have:
Hope this helps.
Code: Select all
$USER1$/check_uptime -H $HOSTADDRESS$ $ARG1$Be sure to check out our Knowledgebase for helpful articles and solutions!
-
srikanth.kallu
- Posts: 243
- Joined: Thu Jul 26, 2012 10:48 am
Re: Help in uploading a plugin
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.
[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.
-
slansing
- Posts: 7698
- Joined: Mon Apr 23, 2012 4:28 pm
- Location: Travelling through time and space...
Re: Help in uploading a plugin
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.
-
scottwilkerson
- DevOps Engineer
- Posts: 19396
- Joined: Tue Nov 15, 2011 3:11 pm
- Location: Nagios Enterprises
- Contact:
Re: Help in uploading a plugin
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
Lets remember to make the file executable
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
Code: Select all
command[check_uptime]=/usr/local/nagios/libexec/check_uptimeCode: Select all
chmod +x /usr/local/nagios/libexec/check_uptimeCode: Select all
service xinetd restartTo 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
Code: Select all
$ARG1$ = check_uptime