SNMP Timeticks not returning as days/hours

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.
Locked
DiegoAnjos
Posts: 49
Joined: Thu Feb 14, 2013 9:32 am

SNMP Timeticks not returning as days/hours

Post by DiegoAnjos »

Hi

Since I upgraded from Nagios Core from 4.3.0 to 4.3.2 the "Uptime" checks through SNMP returns data as timeticks.

CLI:

Code: Select all

./check_snmp -H X.X.X.X -C snmpcommunity -o sysUpTime.0
RESULT: SNMP OK - 112536996 | DISMAN-EVENT-MIB::sysUpTimeInstance=112536996

WEB UI:SNMP OK - 733630839

How can I get the information as DAYS/HOURS?

Info:
Nagios Core 4.3.2
Plugins: 2.2.1
net-snmp 5.7.2
scottwilkerson
DevOps Engineer
Posts: 19396
Joined: Tue Nov 15, 2011 3:11 pm
Location: Nagios Enterprises
Contact:

Re: SNMP Timeticks not returning as days/hours

Post by scottwilkerson »

You would need to either create a wrapper plugin that does the math calculation, or find on on the exchange that does.

I think this plugin offers what you are looking for
https://exchange.nagios.org/directory/P ... MP/details
Former Nagios employee
Creator:
ahumandesign.com
enneagrams.com
User avatar
tacolover101
Posts: 432
Joined: Mon Apr 10, 2017 11:55 am

Re: SNMP Timeticks not returning as days/hours

Post by tacolover101 »

here you go. i hacked this together. i even mixed sed and cut. :shock:

you'll need to address the variable replacing as you please. it would be easy enough to substitute $1 / $2 though.

Code: Select all

[root@localhost libexec]# ./test.sh
29 days, 0:51:14.82 | uptime=250867482

Code: Select all

#!/bin/bash
data=$(snmpget -v2c -c community -mALL hostaddress 1.3.6.1.2.1.1.3.0 | sed -e 's/.*(\(.*\))/\1/')
human=$(echo $data | cut -d ' ' -f 2,3,4)
perf=$(echo $data | cut -d ' ' -f 1)
echo "$human | uptime=$perf"
scottwilkerson
DevOps Engineer
Posts: 19396
Joined: Tue Nov 15, 2011 3:11 pm
Location: Nagios Enterprises
Contact:

Re: SNMP Timeticks not returning as days/hours

Post by scottwilkerson »

tacolover101 wrote:here you go. i hacked this together. i even mixed sed and cut. :shock:

you'll need to address the variable replacing as you please. it would be easy enough to substitute $1 / $2 though.

Code: Select all

[root@localhost libexec]# ./test.sh
29 days, 0:51:14.82 | uptime=250867482

Code: Select all

#!/bin/bash
data=$(snmpget -v2c -c community -mALL hostaddress 1.3.6.1.2.1.1.3.0 | sed -e 's/.*(\(.*\))/\1/')
human=$(echo $data | cut -d ' ' -f 2,3,4)
perf=$(echo $data | cut -d ' ' -f 1)
echo "$human | uptime=$perf"
nice, thanks @tacolover101
Former Nagios employee
Creator:
ahumandesign.com
enneagrams.com
DiegoAnjos
Posts: 49
Joined: Thu Feb 14, 2013 9:32 am

Re: SNMP Timeticks not returning as days/hours

Post by DiegoAnjos »

@tacolover101
you'll need to address the variable replacing as you please. it would be easy enough to substitute $1 / $2 though.
To help others, I will describe what I had to do to get your script working like it was a default plugin:

Changed your script adding the variables:
#!/bin/bash
data=$(snmpget -v2c -c $1 -mALL $2 1.3.6.1.2.1.1.3.0 | sed -e 's/.*(\(.*\))/\1/')
human=$(echo $data | cut -d ' ' -f 2,3,4)
perf=$(echo $data | cut -d ' ' -f 1)
echo "$human | uptime=$perf"

$1: SNMP communit name
$2: hostname


Saved the script on /usr/local/nagios/libexec naming it as uptime_snmp.sh

On commands.cfg I created a command to call the script:

Code: Select all

define command{
        command_name    uptime_snmp
        command_line    $USER1$/uptime_snmp.sh $ARG1$ $ARG2$
        }
Finally, the service on the host file is written as:
define service{
use generic-service
host_name SWITCH-CORE
service_description UPTIME
check_command uptime_snmp!community!$HOSTADDRESS$
}
Thanks for everyone. That was really a quick reply!
tmcdonald
Posts: 9117
Joined: Mon Sep 23, 2013 8:40 am

Re: SNMP Timeticks not returning as days/hours

Post by tmcdonald »

Glad to hear it! Are we okay to consider this issue resolved?
Former Nagios employee
User avatar
tacolover101
Posts: 432
Joined: Mon Apr 10, 2017 11:55 am

Re: SNMP Timeticks not returning as days/hours

Post by tacolover101 »

DiegoAnjos wrote:@tacolover101
you'll need to address the variable replacing as you please. it would be easy enough to substitute $1 / $2 though.
To help others, I will describe what I had to do to get your script working like it was a default plugin:

Changed your script adding the variables:
#!/bin/bash
data=$(snmpget -v2c -c $1 -mALL $2 1.3.6.1.2.1.1.3.0 | sed -e 's/.*(\(.*\))/\1/')
human=$(echo $data | cut -d ' ' -f 2,3,4)
perf=$(echo $data | cut -d ' ' -f 1)
echo "$human | uptime=$perf"

$1: SNMP communit name
$2: hostname


Saved the script on /usr/local/nagios/libexec naming it as uptime_snmp.sh

On commands.cfg I created a command to call the script:

Code: Select all

define command{
        command_name    uptime_snmp
        command_line    $USER1$/uptime_snmp.sh $ARG1$ $ARG2$
        }
Finally, the service on the host file is written as:
define service{
use generic-service
host_name SWITCH-CORE
service_description UPTIME
check_command uptime_snmp!community!$HOSTADDRESS$
}
Thanks for everyone. That was really a quick reply!
no problem, thanks for explaining the rest of it. :)
Locked