Search Exchange
Search All Sites
Nagios Live Webinars
Let our experts show you how Nagios can help your organization.Login
Directory Tree
check_uptime / check_snmp_uptime
0.521
2012-10-05
- Nagios 1.x
- Nagios 2.x
- Nagios 3.x
- Nagios XI
- Nagios Fusion
GPL
147863
File | Description |
---|---|
check_uptime.pl | check_uptime.pl - version 0.42 (Feb 2012) |
check_uptime.pl | check_uptime.pl - version 0.521 (Oct 2012) |
Meet The New Nagios Core Services Platform
Built on over 25 years of monitoring experience, the Nagios Core Services Platform provides insightful monitoring dashboards, time-saving monitoring wizards, and unmatched ease of use. Use it for free indefinitely.
Monitoring Made Magically Better
- Nagios Core on Overdrive
- Powerful Monitoring Dashboards
- Time-Saving Configuration Wizards
- Open Source Powered Monitoring On Steroids
- And So Much More!
In addition to uptime it will also return system name and unix kernel version. It will try to auto-detect type of remote system, one of 4 types can also be specified: local,win,unix-host,unix-sys
Documentation is in plugin code as usual for all my plugins.
Here are parts of it:
The plugin can either retrieve information from local system (when you run it through check_nrpe for example) or by SNMP from remote system.
On local system it will execute standard unix 'uptime' and 'uname -a'.
On a remote system it'll retrieve data from sysSystem for system type and use that to decide if further data should be retrieved from
sysUptime (OID 1.3.6.1.2.1.1.3.0) for windows or
hostUptime (OID 1.3.6.1.2.1.25.1.1.0) for unix system or
snmpEngineTime (OID 1.3.6.1.6.3.10.2.1.3) for cisco switches
For information on available options please execute it with --help i.e:
check_uptime.pl --help
As I dont have time for extensive documentation below is all very brief:
1. You can also specify warning and critical thresholds which will give warning or critical alert if system has been up for lees then specified number of minutes. Example:
check_uptime.pl -w 5
Will give warning alert if system has been up for less then 5 minutes
2. For performance data results you can use '-f' option which will give total number of minutes the system has been up.
3. A special case is use of performance to feed data from previous run back into the plugin. This is used to cache results about what type of system it is (you can also directly specify this with -T option) and also means -w and -c threshold values are ignored and instead plugin will issue ONE alert (warning or critical) if system uptime changes from highier value to lower
EXAMPLES =======================================
1. Local server (use with NRPE or on nagios host), warning on < 5 minutes:
define command {
command_name check_uptime
command_line $USER1$/check_uptime.pl -f -w 5
}
2. Local server (use with NRPE or on nagios host),
one critical alert on reboot:
define command {
command_name check_uptime
command_line $USER1$/check_uptime.pl -f -c -P "SERVICEPERFDATA$"
}
3. Remote server SNMP v2, one warning alert on reboot, autodetect and cache type of server:
define command {
command_name check_snmp_uptime_v2
command_line $USER1$/check_uptime.pl -2 -f -w -H $HOSTADDRESS$ -C $_HOSTSNMP_COMMUNITY$ -P "$SERVICEPERFDATA$"
}
4. Remote server SNMP v3, rest as above
define command {
command_name check_snmp_uptime_v3
command_line $USER1$/check_uptime.pl -f -w -H $HOSTADDRESS$ -l $_HOSTSNMP_V3_USER$ -x $_HOSTSNMP_V3_AUTH$ -X $_HOSTSNMP_V3_PRIV$ -L sha,aes -P "$SERVICEPERFDATA$"
}
5. Example of service definition using above
define service{
use std-service
hostgroup_name all_snmp_hosts
service_description SNMP Uptime
max_check_attempts 1
check_command check_snmp_uptime
}
6. And this is optional dependency definition for above which makes every SNMP service (service beloning to SNMP servicegroup) on same host dependent on this SNMP Uptime check. Then if SNMP daemon goes down you only receive one alert
define servicedependency{
service_description SNMP Uptime
dependent_servicegroup_name snmp
}
Here are parts of it:
The plugin can either retrieve information from local system (when you run it through check_nrpe for example) or by SNMP from remote system.
On local system it will execute standard unix 'uptime' and 'uname -a'.
On a remote system it'll retrieve data from sysSystem for system type and use that to decide if further data should be retrieved from
sysUptime (OID 1.3.6.1.2.1.1.3.0) for windows or
hostUptime (OID 1.3.6.1.2.1.25.1.1.0) for unix system or
snmpEngineTime (OID 1.3.6.1.6.3.10.2.1.3) for cisco switches
For information on available options please execute it with --help i.e:
check_uptime.pl --help
As I dont have time for extensive documentation below is all very brief:
1. You can also specify warning and critical thresholds which will give warning or critical alert if system has been up for lees then specified number of minutes. Example:
check_uptime.pl -w 5
Will give warning alert if system has been up for less then 5 minutes
2. For performance data results you can use '-f' option which will give total number of minutes the system has been up.
3. A special case is use of performance to feed data from previous run back into the plugin. This is used to cache results about what type of system it is (you can also directly specify this with -T option) and also means -w and -c threshold values are ignored and instead plugin will issue ONE alert (warning or critical) if system uptime changes from highier value to lower
EXAMPLES =======================================
1. Local server (use with NRPE or on nagios host), warning on < 5 minutes:
define command {
command_name check_uptime
command_line $USER1$/check_uptime.pl -f -w 5
}
2. Local server (use with NRPE or on nagios host),
one critical alert on reboot:
define command {
command_name check_uptime
command_line $USER1$/check_uptime.pl -f -c -P "SERVICEPERFDATA$"
}
3. Remote server SNMP v2, one warning alert on reboot, autodetect and cache type of server:
define command {
command_name check_snmp_uptime_v2
command_line $USER1$/check_uptime.pl -2 -f -w -H $HOSTADDRESS$ -C $_HOSTSNMP_COMMUNITY$ -P "$SERVICEPERFDATA$"
}
4. Remote server SNMP v3, rest as above
define command {
command_name check_snmp_uptime_v3
command_line $USER1$/check_uptime.pl -f -w -H $HOSTADDRESS$ -l $_HOSTSNMP_V3_USER$ -x $_HOSTSNMP_V3_AUTH$ -X $_HOSTSNMP_V3_PRIV$ -L sha,aes -P "$SERVICEPERFDATA$"
}
5. Example of service definition using above
define service{
use std-service
hostgroup_name all_snmp_hosts
service_description SNMP Uptime
max_check_attempts 1
check_command check_snmp_uptime
}
6. And this is optional dependency definition for above which makes every SNMP service (service beloning to SNMP servicegroup) on same host dependent on this SNMP Uptime check. Then if SNMP daemon goes down you only receive one alert
define servicedependency{
service_description SNMP Uptime
dependent_servicegroup_name snmp
}
Reviews (4)
byagentdavidson, May 8, 2017
Hi Willix -
I couldn't get the -net flag to work but I updated the $oid_engineTime as follows:-
-my $oid_engineTime = '1.3.6.1.6.3.10.2.1.3'; # SNMP-FRAMEWORK-MIB
+my $oid_engineTime = '1.3.6.1.6.3.10.2.1.3.0'; # SNMP-FRAMEWORK-MIB
It appears to need the dot zero on the end of it.
Cheers
Matt
I couldn't get the -net flag to work but I updated the $oid_engineTime as follows:-
-my $oid_engineTime = '1.3.6.1.6.3.10.2.1.3'; # SNMP-FRAMEWORK-MIB
+my $oid_engineTime = '1.3.6.1.6.3.10.2.1.3.0'; # SNMP-FRAMEWORK-MIB
It appears to need the dot zero on the end of it.
Cheers
Matt
byShaggySS, February 8, 2017
I have tried many different checks and by far this is the most forgiving (so many error check) to ensure its easy to use and will work for most things. I am using it to monitor the uptime of my Shoretel Switches. A bug was found if they run over 99 days. The one request I have is allow me to sent warncritical if X device has been up for so many days or minute. The current version only allows you to set warn if less than as of 2/2017.
bybasdoorn, January 17, 2015
Works great with debian 7.7. I needed IPv6 support so created a patch to add support for it using the -6 or --use-ipv6 parameters, attached below. If it is up to standards, please include it in future versions as more and more systems are using IPv6 (only).
--- check_uptime.pl 2015-01-17 18:30:29.885907443 +0100
+++ check_uptime_w_ipv6.pl 2015-01-17 18:19:23.209912963 +0100
@@ -213,6 +213,7 @@
my $o_warn= undef; # WARNING alert if system has been up for \$o_host,
'p:i' => \$o_port, 'port:i' => \$o_port,
'C:s' => \$o_community, 'community:s' => \$o_community,
- '2' => \$o_version2, 'v2c' => \$o_version2,
+ '2' => \$o_version2, 'v2c' => \$o_version2,
'l:s' => \$o_login, 'login:s' => \$o_login,
'x:s' => \$o_passwd, 'passwd:s' => \$o_passwd,
'X:s' => \$o_privpass, 'privpass:s' => \$o_privpass,
@@ -376,6 +379,7 @@
'label:s' => \$o_label,
'P:s' => \$o_prevperf, 'prev_perfdata:s' => \$o_prevperf,
'T:s' => \$o_type, 'type:s' => \$o_type,
+ '6' => \$o_domain, 'use-ipv6' => \$o_domain,
);
if (defined ($o_help) ) { help(); exit $ERRORS{"UNKNOWN"}};
if (defined($o_version)) { p_version(); exit $ERRORS{"UNKNOWN"}};
@@ -445,11 +449,19 @@
sub create_snmp_session {
my ($session,$error);
+ # Check IPv6
+ if (defined ($o_domain)) {
+ $o_domain="udp/ipv6";
+ } else {
+ $o_domain="udp/ipv4";
+ }
+
if ( defined($o_login) && defined($o_passwd)) {
# SNMPv3 login
if (!defined ($o_privpass)) {
verb("SNMPv3 AuthNoPriv login : $o_login, $o_authproto");
($session, $error) = Net::SNMP->session(
+ -domain => $o_domain,
-hostname => $o_host,
-version => '3',
-port => $o_port,
@@ -461,6 +473,7 @@
} else {
verb("SNMPv3 AuthPriv login : $o_login, $o_authproto, $o_privproto");
($session, $error) = Net::SNMP->session(
+ -domain => $o_domain,
-hostname => $o_host,
-version => '3',
-username => $o_login,
@@ -477,6 +490,7 @@
# SNMPv2c Login
verb("SNMP v2c login");
($session, $error) = Net::SNMP->session(
+ -domain => $o_domain,
-hostname => $o_host,
-version => 2,
-community => $o_community,
@@ -487,6 +501,7 @@
# SNMPV1 login
verb("SNMP v1 login");
($session, $error) = Net::SNMP->session(
+ -domain => $o_domain,
-hostname => $o_host,
-community => $o_community,
-port => $o_port,
--- check_uptime.pl 2015-01-17 18:30:29.885907443 +0100
+++ check_uptime_w_ipv6.pl 2015-01-17 18:19:23.209912963 +0100
@@ -213,6 +213,7 @@
my $o_warn= undef; # WARNING alert if system has been up for \$o_host,
'p:i' => \$o_port, 'port:i' => \$o_port,
'C:s' => \$o_community, 'community:s' => \$o_community,
- '2' => \$o_version2, 'v2c' => \$o_version2,
+ '2' => \$o_version2, 'v2c' => \$o_version2,
'l:s' => \$o_login, 'login:s' => \$o_login,
'x:s' => \$o_passwd, 'passwd:s' => \$o_passwd,
'X:s' => \$o_privpass, 'privpass:s' => \$o_privpass,
@@ -376,6 +379,7 @@
'label:s' => \$o_label,
'P:s' => \$o_prevperf, 'prev_perfdata:s' => \$o_prevperf,
'T:s' => \$o_type, 'type:s' => \$o_type,
+ '6' => \$o_domain, 'use-ipv6' => \$o_domain,
);
if (defined ($o_help) ) { help(); exit $ERRORS{"UNKNOWN"}};
if (defined($o_version)) { p_version(); exit $ERRORS{"UNKNOWN"}};
@@ -445,11 +449,19 @@
sub create_snmp_session {
my ($session,$error);
+ # Check IPv6
+ if (defined ($o_domain)) {
+ $o_domain="udp/ipv6";
+ } else {
+ $o_domain="udp/ipv4";
+ }
+
if ( defined($o_login) && defined($o_passwd)) {
# SNMPv3 login
if (!defined ($o_privpass)) {
verb("SNMPv3 AuthNoPriv login : $o_login, $o_authproto");
($session, $error) = Net::SNMP->session(
+ -domain => $o_domain,
-hostname => $o_host,
-version => '3',
-port => $o_port,
@@ -461,6 +473,7 @@
} else {
verb("SNMPv3 AuthPriv login : $o_login, $o_authproto, $o_privproto");
($session, $error) = Net::SNMP->session(
+ -domain => $o_domain,
-hostname => $o_host,
-version => '3',
-username => $o_login,
@@ -477,6 +490,7 @@
# SNMPv2c Login
verb("SNMP v2c login");
($session, $error) = Net::SNMP->session(
+ -domain => $o_domain,
-hostname => $o_host,
-version => 2,
-community => $o_community,
@@ -487,6 +501,7 @@
# SNMPV1 login
verb("SNMP v1 login");
($session, $error) = Net::SNMP->session(
+ -domain => $o_domain,
-hostname => $o_host,
-community => $o_community,
-port => $o_port,
byRom_UA, January 11, 2012
Hi,
I get an issue using the plugin when the system has an uptime value with 0 hour. For example, when the system is up for 1 day and 35 minutes(( 9:27AM up 1 day, 35 mins ). The $uptime_output does not match one of the value defined and running the script in verbos mode return an error.
I added this code just after the line 482 :
elsif ($uptime_output =~ /ups+(d+)s+days?,s+(d+)s+min/) {
($days, $hrs, $mins) = ($1,0,$2);
$uptime_info = "up $days days $mins minutes";
}
Best regards,
Romain
I get an issue using the plugin when the system has an uptime value with 0 hour. For example, when the system is up for 1 day and 35 minutes(( 9:27AM up 1 day, 35 mins ). The $uptime_output does not match one of the value defined and running the script in verbos mode return an error.
I added this code just after the line 482 :
elsif ($uptime_output =~ /ups+(d+)s+days?,s+(d+)s+min/) {
($days, $hrs, $mins) = ($1,0,$2);
$uptime_info = "up $days days $mins minutes";
}
Best regards,
Romain
Owner's reply
Thanks for the feedback. I've added this code to just released 0.41 version.