Home Directory

Search Exchange

Search All Sites

Nagios Live Webinars

Let our experts show you how Nagios can help your organization.

Contact Us

Phone: 1-888-NAGIOS-1
Email: sales@nagios.com

Login

Remember Me

Directory

pelicanmedia

Reviews(4)
bypelicanmedia, July 9, 2018
Telegram Notifications
Hi,

Thanks for the scripts... but...

There needs to be a lot more clarification (and spell checking) as to what variables need to go where and what they mean (as one of the other reviews say also).

i.e. _telegram XXXXXXXXX
Where is this variable? As the reference to call it is "$_CONTACTTELEGRAM$"

i.e _SENDTELEGRAM 1
Where is this variable? As the reference to call it is $_HOSTSENDTELEGRAM$ and $_SERVICESENDTELEGRAM$ (NOT in " ").

Thanks
bypelicanmedia, June 27, 2018
Hi,

Firstly, thanks for the script(s).

BUT... I am getting the opposite results on the web console than I am from the command line eg:

My check_file_exists file =
#!/bin/sh
#
# Author : Diego Martin Gardella [dgardella@gmail.com]
# Desc : Plugin to verify if a file exists
#
# v1.0: Initial version by (Diego Martin Gardella [dgardella@gmail.com])
# v1.1: Add negate support (Elan Ruusamäe )
# v1.2: Also check if file is folder (Simon Smit)

PROGNAME=`basename $0`
PROGPATH=`echo $0 | sed -e 's,[\\/][^\\/][^\\/]*$,,'`

. $PROGPATH/utils.sh

usage() {
echo "Usage: $PROGRAM [-n] [file]
Options:
-n, --negate negate the result
"
}

state_name() {
case "$STATE" in
$STATE_OK)
echo OK
;;
$STATE_CRITICAL)
echo CRITICAL
;;
esac
}

exists() {
$negate && STATE=$STATE_CRITICAL || STATE=$STATE_OK
echo "$(state_name) - $1 EXISTS"
}

exists_dir() {
$negate && STATE=$STATE_CRITICAL || STATE=$STATE_OK
echo "$(state_name) - $1 EXISTS :: Directory"
}

not_exists() {
$negate && STATE=$STATE_OK || STATE=$STATE_CRITICAL
echo "$(state_name) - $1 Does NOT exist"
}

# parse command line args
t=$(getopt -o n --long negate -n "$PROGNAME" -- "$@")
[ $? != 0 ] && exit $?
eval set -- "$t"

negate=false
while :; do
case "$1" in
-n|--negate)
negate=true
;;
--)
shift
break
;;
*)
echo >&2 "$PROGRAM: Internal error: [$1] not recognized!"
exit 1
;;
esac
shift
done

STATE=$STATE_UNKNOWN
if [ "$1" = "" ]; then
usage
exit $STATE
fi

if [ -f "$1" ]; then
exists "$1"
elif [ -d "$1" ]; then
exists_dir "$1"
else
not_exists "$1"
fi
exit $STATE

==========
In my commands.cfg =
# 'check_file_exists' command definition
define command {
command_name check_file_exists
command_line $USER1$/check_file_exists $ARG1$
}

==========
In my_server_name.cfg =
define service{
use generic-service
host_name my_server_name
service_description Check Backup - Nagios
check_command heck_file_exist!/root/backups/nagios/nagios.tar.gz
}

==========
When I run from the command line...
[root@centos libexec]# ./check_file_exists /root/backups/nagios
OK - /root/backups/nagios EXISTS :: Directory
[root@centos libexec]# ./check_file_exists /root/backups/nagios/nagios.tar.gz
OK - /root/backups/nagios/nagios.tar.gz EXISTS
[root@centos libexec]# ./check_file_exists /root/backups/nagios/nagios.tar
CRITICAL - /root/backups/nagios/nagios.tar Does NOT exist

In the web console...

Check Backup - Nagios | CRITICAL | 27-06-2018 14:22:37 | 0d 0h 0m 30s | 1/3 | CRITICAL - /root/backups/nagios/nagios.tar.gz Does NOT exist

Any ideas as to why I would be getting the opposite result ??

Thanks
bypelicanmedia, April 5, 2018
Thank you for this !!

I have been hunting and testing for MONTHS to find a check_uptime script that works correctly. This is the only one that does with the different results (depending on time up) from 'uptime'. i.e Minutes, Hours & Minutes, Days & Minutes, Day & Hours & Minutes.

I have made a few adjustments to mine as I have no need for warnings, just for monitoring:

==========
#!/bin/sh

UPTIME_REPORT=`uptime | tr -d ","`

if echo $UPTIME_REPORT | grep -i day > /dev/null ; then

if echo $UPTIME_REPORT | grep -i "min" > /dev/null ; then

DAYS=`echo $UPTIME_REPORT | awk '{ print $3 }'`
MINUTES=`echo $UPTIME_REPORT | awk '{ print $5}'`

else
DAYS=`echo $UPTIME_REPORT | awk '{ print $3 }'`
HOURS=`echo $UPTIME_REPORT | awk '{ print $5}' | cut -f1 -d":"`
MINUTES=`echo $UPTIME_REPORT | awk '{ print $5}' | cut -f2 -d":"`
fi

elif #in AIX 5:00 will show up as 5 hours, and in Solaris 2.6 as 5 hr(s)
echo $UPTIME_REPORT | egrep -e "hour|hr\(s\)" > /dev/null ; then
HOURS=`echo $UPTIME_REPORT | awk '{ print $3}'`
else
echo $UPTIME_REPORT | awk '{ print $3}' | grep ":" > /dev/null && \
HOURS=`echo $UPTIME_REPORT | awk '{ print $3}' | cut -f1 -d":"`
MINUTES=`echo $UPTIME_REPORT | awk '{ print $3}' | cut -f2 -d":"`
fi

UPTIME_MSG="${DAYS:+$DAYS Days,} ${HOURS:+$HOURS Hours,} $MINUTES Minutes"

echo System Uptime - $UPTIME_MSG
==========

I now have this running on CentOS, Ubuntu and Raspberry Pi servers, all running perfectly!

System Uptime - 0 Minutes
System Uptime - 4 Hours, 19 Minutes
System Uptime - 2 Days, 8 Hours, 54 Minutes
bypelicanmedia, July 6, 2017
...incorrect results depending on time format...

Using:

struptime=`uptime | awk '{print $2,$3,$4,$5}'`

if [[ $struptime == *day* ]]; then
struptime1=${struptime%,}
else
struptime1=${struptime%, *}
fi

strdayshours=${struptime1%%:*}' hours '
strminutes=${struptime1##*:}
strminutes1=${strminutes%%,*}' minutes'

echo "System Uptime -" $strdayshours$strminutes1
exit 0


Machine up for 10 minutes:
Command = uptime
Result = 12:36:04 up 10 min, 1 user, load average: 0.00, 0.00, 0.00
Command = uptime | awk '{print $2,$3,$4,$5}'
Result = up 10 min, 1
Command = /usr/local/nagios/libexec/check_nrpe -H 127.0.0.1 -c check_uptime
Result = System Uptime - up 10 min hours up 10 min minutes

Machine up for 2 hours:
Command = uptime
Result = 12:48:27 up 2:02, 2 users, load average: 0.12, 0.06, 0.06
Command = uptime | awk '{print $2,$3,$4,$5}'
Result = up 2:02, 2 users,
Command = /usr/local/nagios/libexec/check_nrpe -H 127.0.0.1 -c check_uptime
Result = System Uptime - up 2 hours 02 minutes

Arguments $2,$3,$4,$5 are different depending if the time is in HH:MM format it works (not sure on days yet as have rebooted my servers) but breaks if it contains 'min'.

Guess it needs another if statement, but I am not knowledgable enough to work it out...