Nagios check_snmp / Uptime

Support forum for Nagios Core, Nagios Plugins, NCPA, NRPE, NSCA, NDOUtils and more. Engage with the community of users including those using the open source solutions.
Expertise
Posts: 20
Joined: Thu Apr 23, 2015 8:20 am

Nagios check_snmp / Uptime

Post by Expertise »

Hi,

i trying to check uptime of a cameraIP and switchDLINK, and Localhost. i find to make it for winserver with nsclient++ and the check is green in nagios but for other impossible....

with "check_snmp" result critical (plugin timed out), with uptime_by_snmp critical too(code of 13 bound...), but in terminal with snmpget ...... its worked fine and i get the good result.

Image
jdalrymple
Skynet Drone
Posts: 2620
Joined: Wed Feb 11, 2015 1:56 pm

Re: Nagios check_snmp / Uptime

Post by jdalrymple »

Looks like one of your problems is that not all the necessary MIBs are loaded properly.

I think to start it would be very good if you could post the relevant parts of your service configuration files and commands.cfg

Can you share these please? If you need to you can mask out the community string.
Expertise
Posts: 20
Joined: Thu Apr 23, 2015 8:20 am

Re: Nagios check_snmp / Uptime

Post by Expertise »

where is my reply?? i reply with code, commands and service of my camera, switch ????
Expertise
Posts: 20
Joined: Thu Apr 23, 2015 8:20 am

Re: Nagios check_snmp / Uptime

Post by Expertise »

service

Code: Select all

# Monitor uptime via SNMP

define service{
	use			generic-service	; Inherit values from a template
	host_name		cameratest196
	service_description	Uptime	
	check_command		check_snmp! -c public -o sysUpTime.0
	}

# Monitor uptime_by_snmp
 
define service {
	host_name                      cameratest196	
	service_description            Uptime_by_SNMP
	check_command                  uptime_by_snmp!public
	use                            generic-service
	normal_check_interval          1
	}
commands

Code: Select all

# 'check_uptime' command definition for linux hosts
define command{
        command_name    check_time
        command_line    $USER1$/check_time -H $HOSTADDRESS$
}

# 'uptime_by_snmp' command definition 
define command {
	command_name                    uptime_by_snmp
	command_line                    /usr/local/nagios/libexec/uptime_by_snmp $HOSTADDRESS$ $ARG1$
	}
jdalrymple
Skynet Drone
Posts: 2620
Joined: Wed Feb 11, 2015 1:56 pm

Re: Nagios check_snmp / Uptime

Post by jdalrymple »

Expertise wrote:service
# Monitor uptime via SNMP

Code: Select all

define service{
	use			generic-service	; Inherit values from a template
	host_name		cameratest196
	service_description	Uptime	
	check_command		check_snmp! -c public -o sysUpTime.0
	}
Can we see the check_snmp command definition in commands.cfg to troubleshoot this one? It looks pretty good.
You may also want to run the following from the command line just to be sure there isn't a communication problem:

Code: Select all

snmpget -v 2c -c public <cameratest196 IP Addr> sysUpTime.0
Expertise wrote: # Monitor uptime_by_snmp

Code: Select all

define service {
	host_name                      cameratest196	
	service_description            Uptime_by_SNMP
	check_command                  uptime_by_snmp!public
	use                            generic-service
	normal_check_interval          1
	}
This looks OK... but...
Expertise wrote:

Code: Select all

# 'uptime_by_snmp' command definition 
define command {
	command_name                    uptime_by_snmp
	command_line                    /usr/local/nagios/libexec/uptime_by_snmp $HOSTADDRESS$ $ARG1$
	}
Does the binary /usr/local/nagios/libexec/uptime_by_snmp really exist?
Expertise wrote: commands

Code: Select all

# 'check_uptime' command definition for linux hosts
define command{
        command_name    check_time
        command_line    $USER1$/check_time -H $HOSTADDRESS$
}
Check time uses the rdate protocol just to see if the time between the 2 servers matches. Is that really what you want to do? Most people would be best serviced using check_ntp_time.
Expertise
Posts: 20
Joined: Thu Apr 23, 2015 8:20 am

Re: Nagios check_snmp / Uptime

Post by Expertise »

i'm NOOB in all linux and nagios and i try to configure nagios for supervision serveur, cameraIP, switch ect... and i'm learning alone then i try for begenning to display "uptime" (life line i think in english) of my camera, just like uptime of my win computer (its work directly with check_nt and nsclient++) i thinking its simple but i cant make just it LOL ;)

edit: i change command check_time to check_uptime and service too in localhost and now i have this message
"Usage:
check_uptime [-u uom] [-w threshold] [-c threshold] [-t] [-h] [-vvv] [-V]"

# 'check_snmp' command definition
define command{
command_name check_snmp
command_line $USER1$/check_snmp -H $HOSTADDRESS$ $ARG1$
}

"command generic i cant touch it"

1-snmpget:

snmpget -v1 -c public 192.168.52.196 1.3.6.1.2.1.1.3.0 --> this mine GOOD
iso.3.6.1.2.1.1.3.0 = Timeticks: (25857410) 2 days, 23:49:34.10 --> return "uptime"

snmpget -v 2c -c public 192.168.52.196 sysUpTime.0
sysUpTime.0: Unknown Object Identifier (Sub-id not found: (top) -> sysUpTime) -->your ERROR

2-uptime_by_snmp

Yes it's doesnt exist and i find the script, i creat file uptime_by_snmp.pl and i deposit it in folder libexec but not work too

Code: Select all

#!/bin/sh
#
# 2003-01-11, Fredrik Wanglund
#
# This plugin gets the uptime from a host via snmp.
# 
# To use the plugn, do the following:
#
# First, create a checkcommand (typically in etc/checkcommands.cfg):
#
# define command {
# command_name                    uptime_by_snmp
# command_line                    /usr/local/nagios/libexec/uptime_by_snmp $HOSTADDRESS$ $ARG1$
# }
# 
# If your Nagios-plugin is not located in /usr/local/nagios/libexec/, 
# You have to change the path in the command-definition AND the
# variable NAGIOSPLUGSDIR below.
#
# Second, Add a service-definition (typically in etc/services.cfg):
#
# define service {
# host_name                      server
# service_description            Uptime
# check_command                  uptime_by_snmp!public
# use                            generic-service
# normal_check_interval          10
# }
# 
# Replace the 'use' statement with whatever template you would like to use,
# or fill up the definition with required parameters if you dont want to
# use any template.
#
# The arguments to the 'check_command' is:
# 1) The command-name, disk_by_snmp
# 2) The SNMP community-string
#
# READY.
#
#
#
# Change this if you have installed NAgios in a non-default place:
NAGIOSPLUGSDIR=/usr/local/nagios/libexec
UPTIMESDIR=/usr/local/nagios/uptimes


UPT=`$NAGIOSPLUGSDIR/check_snmp -H $1 -o .1.3.6.1.2.1.1.3.0 -C $2`

RES=$?

if [ $RES = 0 ]; then
	
	TICKS=`echo $UPT|cut -d "(" -f 2|cut -d ")" -f 1`
	if [ -f $UPTIMESDIR/$1 ]; then
		if [ -s $UPTIMESDIR/$1 ]; then
			MAXTICKS=`cat $UPTIMESDIR/$1|cut -d ":" -f 2`
		else
			MAXTICKS=0
		fi
		if [ $TICKS -gt $MAXTICKS ]; then
			DATE=`date "+%s"`
			echo "$DATE, $1, $MAXTICKS, $TICKS" >> /tmp/ticks
			echo "$DATE:$TICKS" > $UPTIMESDIR/$1
		fi
	else
	echo "$1: $TICKS" >> /tmp/ticks
	fi

	RET=`echo $UPT|cut -d ")" -f 2`
else
	RET=$UPT
	RES=1
fi

RET="Uptime: $RET"
echo $RET
exit $RES


jdalrymple
Skynet Drone
Posts: 2620
Joined: Wed Feb 11, 2015 1:56 pm

Re: Nagios check_snmp / Uptime

Post by jdalrymple »

Expertise wrote:

Code: Select all

# 'check_uptime' command definition for linux hosts
define command{
        command_name    check_time
        command_line    $USER1$/check_time -H $HOSTADDRESS$
}
edit: i change command check_time to check_uptime and service too in localhost and now i have this message

Code: Select all

Usage:
check_uptime [-u uom] [-w threshold] [-c threshold] [-t] [-h] [-vvv] [-V]"

# 'check_snmp' command definition
define command{
        command_name    check_snmp
        command_line    $USER1$/check_snmp -H $HOSTADDRESS$ $ARG1$
        }
I'm wondering if you didn't accidentally change it in your command definition instead of in your service definition. You cannot change it in your command definition - the command check_uptime will not accept a -H argument
Expertise wrote:1-snmpget:

snmpget -v1 -c public 192.168.52.196 1.3.6.1.2.1.1.3.0 --> this mine GOOD
iso.3.6.1.2.1.1.3.0 = Timeticks: (25857410) 2 days, 23:49:34.10 --> return "uptime"

snmpget -v 2c -c public 192.168.52.196 sysUpTime.0
sysUpTime.0: Unknown Object Identifier (Sub-id not found: (top) -> sysUpTime) -->your ERROR
This indicates that you don't have your MIBs loaded. Either fix SNMP so it's loading your MIBs or change this:

Code: Select all

define service{
   use         generic-service   ; Inherit values from a template
   host_name      cameratest196
   service_description   Uptime   
   check_command      check_snmp! -c public -o sysUpTime.0
   }
To this:

Code: Select all

define service{
   use         generic-service   ; Inherit values from a template
   host_name      cameratest196
   service_description   Uptime   
   check_command      check_snmp! -c public -o .1.3.6.1.2.1.1.3.0
   }
Expertise wrote:2-uptime_by_snmp

Yes it's doesnt exist and i find the script, i creat file uptime_by_snmp.pl and i deposit it in folder libexec but not work too

Code: Select all

#!/bin/sh
#
# 2003-01-11, Fredrik Wanglund
#
# This plugin gets the uptime from a host via snmp.
# 
# To use the plugn, do the following:
#
# First, create a checkcommand (typically in etc/checkcommands.cfg):
#
# define command {
# command_name                    uptime_by_snmp
# command_line                    /usr/local/nagios/libexec/uptime_by_snmp $HOSTADDRESS$ $ARG1$
# }
# 
# If your Nagios-plugin is not located in /usr/local/nagios/libexec/, 
# You have to change the path in the command-definition AND the
# variable NAGIOSPLUGSDIR below.
#
# Second, Add a service-definition (typically in etc/services.cfg):
#
# define service {
# host_name                      server
# service_description            Uptime
# check_command                  uptime_by_snmp!public
# use                            generic-service
# normal_check_interval          10
# }
# 
# Replace the 'use' statement with whatever template you would like to use,
# or fill up the definition with required parameters if you dont want to
# use any template.
#
# The arguments to the 'check_command' is:
# 1) The command-name, disk_by_snmp
# 2) The SNMP community-string
#
# READY.
#
#
#
# Change this if you have installed NAgios in a non-default place:
NAGIOSPLUGSDIR=/usr/local/nagios/libexec
UPTIMESDIR=/usr/local/nagios/uptimes


UPT=`$NAGIOSPLUGSDIR/check_snmp -H $1 -o .1.3.6.1.2.1.1.3.0 -C $2`

RES=$?

if [ $RES = 0 ]; then
	
	TICKS=`echo $UPT|cut -d "(" -f 2|cut -d ")" -f 1`
	if [ -f $UPTIMESDIR/$1 ]; then
		if [ -s $UPTIMESDIR/$1 ]; then
			MAXTICKS=`cat $UPTIMESDIR/$1|cut -d ":" -f 2`
		else
			MAXTICKS=0
		fi
		if [ $TICKS -gt $MAXTICKS ]; then
			DATE=`date "+%s"`
			echo "$DATE, $1, $MAXTICKS, $TICKS" >> /tmp/ticks
			echo "$DATE:$TICKS" > $UPTIMESDIR/$1
		fi
	else
	echo "$1: $TICKS" >> /tmp/ticks
	fi

	RET=`echo $UPT|cut -d ")" -f 2`
else
	RET=$UPT
	RES=1
fi

RET="Uptime: $RET"
echo $RET
exit $RES


You'll need to change this:

Code: Select all

# 'uptime_by_snmp' command definition
define command {
   command_name                    uptime_by_snmp
   command_line                    /usr/local/nagios/libexec/uptime_by_snmp $HOSTADDRESS$ $ARG1$
   }
to this:

Code: Select all

# 'uptime_by_snmp' command definition
define command {
   command_name                    uptime_by_snmp
   command_line                    /usr/local/nagios/libexec/uptime_by_snmp.pl $HOSTADDRESS$ $ARG1$
   }
Expertise
Posts: 20
Joined: Thu Apr 23, 2015 8:20 am

Re: Nagios check_snmp / Uptime

Post by Expertise »

1-snmpget :

i change sysUpTime.0 to .1.3.6....... and now it's works THXXXXXXX.

then how to use MIB, if i dont have mib i do using "numbers" for request .1.3.6... and if i have mib i can use it's "name" sysUpTime.0 ?? now how to load MIB ;).

i DL the mib of my switch but where i place it ?
(http://tsd.dlink.com.tw/downloads2008detail.asp)
"MIB:DGS-1210-08P/24P D1 MIB of FW v4.10.023 (for DEU) "

mine is DGS-1210-08P i take this but its can't worked too (i dont know use it hihi).

2-uptime_by_snmp :

i change command and i add " .pl " but not working too

"(Return code of 13 is out of bounds) "

my script his in the good folder.
jdalrymple
Skynet Drone
Posts: 2620
Joined: Wed Feb 11, 2015 1:56 pm

Re: Nagios check_snmp / Uptime

Post by jdalrymple »

Expertise wrote:now how to load MIB ;).

i DL the mib of my switch but where i place it ?
Read SNMP documentation here: http://www.net-snmp.org/wiki/index.php/ ... ading_MIBS
Also you don't need to have any device specific MIBs for sysUpTime.0 - all SNMP enabled devices should answer that query, and yours clearly does.
Expertise wrote:i change command and i add " .pl " but not working too

"(Return code of 13 is out of bounds) "

my script his in the good folder.

It might be good to just try and run your command as user Nagios:

Code: Select all

sudo su nagios -c "/usr/local/nagios/libexec/uptime_by_snmp.pl <IP of HOST>"
I don't know what the usage of that script is supposed to be, so maybe that is the issue.
Expertise
Posts: 20
Joined: Thu Apr 23, 2015 8:20 am

Re: Nagios check_snmp / Uptime

Post by Expertise »

HI, very thank you for your help, now I understand little more hihi ;)

1-snmpget --> OK
"i just place all my MIB of archive.zip in the folder MIB and its works"

I learn with you in command if i dont have MIB i search uptime with number 1.3.XXXXX work without MIB, and if i have MIB i use this call name sysUpTime.0.

2-script.pl --> Forbiden
with all MIB in right folder its works good and my SWITCH are OK "uptime", "port 1 linked status"

but its never finish .......

3-MRTG
I install mrtg but i block with a little think, I can't make auto start of refresh all log for mrtg

http://oss.oetiker.ch/mrtg/doc/mrtg-unix-guide.en.html

this code to launch mrtg and I read the tuto but i dont understand how to make symbolique link ect...

Code: Select all

/usr/local/mrtg-2/bin/mrtg /home/mrtg/cfg/mrtg.cfg

Code: Select all

You can also run mrtg as a daemon process by adding the line

RunAsDaemon: Yes

to your mrtg configuration file and then creating a startup script in your system startup sequence. Unfortunately, adding startup scripts differs widely amongst different unix systems. The modern ones normally have a directory called /etc/init.d or /etc/rc.d/init.d where you put scripts which starts the process you want to run when the system boots. Further you must create a symbolic link in /etc/rc3.d or /etc/rc.d/rc?.d called S65mrtg (this is just a sample name ... it is just important that it starts with S followed by a two digit number). If you are not sure about this, make sure you consult the documentation of your system to make sure you get this right.

A minimal script to put into init.d might look like this:

 #! /bin/sh
 cd /usr/local/mrtg-2.17.4/bin && ./mrtg --user=mrtg-user \
       /home/httpd/mrtg/mrtg.cfg  --logging /var/log/mrtg.log                  

Image
Locked