1

Forgive me if this is answered somewhere already - I find lots of similar questions but nothing that seems to fix my issue.

I am simply testing the uptime of some windows servers in nagios, and if it's over a certain value I wish to alert on that.

It was working yesterday, and at some point I seem to have broken things but can't identify exactly what's wrong.

Firstly, as root the test works:

./libexec/check_uptime.sh x.x.x.x 28 30
1449919
OK. Uptime 16 Days.

As nagios, via su - nagios the test works:

su - nagios
-bash-3.2$ pwd
/usr/local/nagios
-bash-3.2$ ./libexec/check_uptime.sh xx.xx.xx.xx 28 30
1449969
OK. Uptime 16 Days.

However I believe the 'correct' way to test is via su - nagios -c ?

su - nagios -c "./libexec/check_uptime.sh 10.36.128.22 28 30"
1450084
OK. Uptime 16 Days.

However the command is failing still in the webpage/daemon

Uptime UNKNOWN  15-03-2016 11:04:24 0d 1h 4m 10s    3/3 0

The command definition looks correct to me:

define command{
    command_name                    check_uptime
    command_line                    $USER1$/check_uptime.sh -H $HOSTADDRESS$ 25 28
}

As is the service definition:

define service{
    use                     generic-service
    hostgroup_name          Windows-Servers
    service_description     Uptime
    check_command           check_uptime
}

Somehow lost the script in an edit, here it is again:

#!/bin/bash

## Shamelessly adapted from http://correctlife.blogspot.de/2011/02/wrapper-on-checkntuptime.html

HOSTADDRESS=$1
MAXWARN=28 # in days
MAXCRIT=30 # in days
MINCRIT=1

STATE_OK=0
STATE_WARNING=1
STATE_CRITICAL=2
STATE_UNKNOWN=3

SECONDS=`/usr/local/nagios/libexec/check_nt -H $HOSTADDRESS -p 12489 -s $ekr3t -v COUNTER -l "\\System\\System Up Time"`
#echo $SECONDS

if [ $SECONDS == 0 ]; then
        echo "UNKNOWN: No uptime recieved. Uptime Value: $SECONDS"
        exit 3
fi

HOURS=$(( $SECONDS / 60 / 60 ))
SECONDSINHOURS=$(( $HOURS * 60 * 60 ))
DAYS=$(( $HOURS / 24 ))
REMAININGSECONDS=$(( $SECONDS - $SECONDSINHOURS ))
MINUTES=$(( $REMAININGSECONDS / 60 ))
FORMEDUPTIME="${DAYS} Days"

if [[ $HOURS -lt $MINCRIT ]]; then
        echo "CRITICAL: System restarted in last hour."
        exit 2
fi

if [[ $DAYS -ge $MAXCRIT ]]; then
    echo "CRITICAL: System up over ${MAXCRIT} Days."
    exit 2
fi

if [[ $DAYS -ge $MAXWARN ]]; then
    echo "WARNING: System up over ${MAXWARN} Days."
    exit 1
fi

echo "OK. Uptime $FORMEDUPTIME."
exit 0
5

1 Answer 1

1

I'm an idiot.

The clue came in the command definition.

At some point I'd helpfully 'added' the -H to it, which obviously meant I was passing -H as the hostname ;)

Should have been:

define command{
command_name                    check_uptime
command_line                    $USER1$/check_uptime.sh $HOSTADDRESS$ 25 28
}

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .