Page 1 of 1
SNMP Timeticks not returning as days/hours
Posted: Wed Aug 30, 2017 3:59 pm
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
Re: SNMP Timeticks not returning as days/hours
Posted: Wed Aug 30, 2017 4:40 pm
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
Re: SNMP Timeticks not returning as days/hours
Posted: Wed Aug 30, 2017 4:57 pm
by tacolover101
here you go. i hacked this together. i even mixed sed and cut.
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"
Re: SNMP Timeticks not returning as days/hours
Posted: Thu Aug 31, 2017 8:49 am
by scottwilkerson
tacolover101 wrote:here you go. i hacked this together. i even mixed sed and cut.
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
Re: SNMP Timeticks not returning as days/hours
Posted: Thu Aug 31, 2017 12:48 pm
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!
Re: SNMP Timeticks not returning as days/hours
Posted: Thu Aug 31, 2017 3:31 pm
by tmcdonald
Glad to hear it! Are we okay to consider this issue resolved?
Re: SNMP Timeticks not returning as days/hours
Posted: Thu Aug 31, 2017 7:23 pm
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.