-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmon
More file actions
executable file
·49 lines (40 loc) · 1.53 KB
/
Copy pathmon
File metadata and controls
executable file
·49 lines (40 loc) · 1.53 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
#!/bin/sh
help_message="\n
This programm gets list of checks for current host from nagios, puts it into a temp CONFIG_FILE\n
and then runs checks on host directly\n
Use -s option to print command, which will be execution\n
USAGE: \n\t$0 -s\n
AUTHOR: \n\thttps://github.com/leoleovich"
while getopts ":s" OPTION; do
case "$OPTION" in
s) SHOW="YES" ;;
*) echo -e $help_message && exit 1 ;;
esac
done
. /etc/montor_config
EXIT_CODE_COLOR_0="2"
EXIT_CODE_COLOR_1="3"
EXIT_CODE_COLOR_2="1"
CONFIG_FILE="/tmp/checks_config"
TEMP_CONFIG_FILE="/tmp/checks_config_temp"
curl -s $URL/config --user $USER:$PASSWORD > $CONFIG_FILE 2>/dev/null || echo "You do not have https access to monitor"
grep -R "^command\[.*\]" /etc/nagios/nrpe* 2>/dev/null >> $CONFIG_FILE
sort < $CONFIG_FILE | uniq > $TEMP_CONFIG_FILE
mv $TEMP_CONFIG_FILE $CONFIG_FILE
curl --silent -L "$URL/thruk/cgi-bin/status.cgi?hidesearch=2&s0_op=~&s0_type=search&s0_value=ho%3A$(hostname)" --user $USER:$PASSWORD | grep "service=" | sed 's/.*service=//g; s/&.*//g' 2>/dev/null |
while read check
do
command=$(sed -n -E '/\['$check'\]/h; ${x;s/.*\] ?= ?(.*)/\1/g;p;}' /tmp/checks_config)
if ! [ -z "$command" ] ; then
if [ "$SHOW" = "YES" ]; then
echo $(grep "\[$check\]" $CONFIG_FILE | tail -1)
fi
result=$(sudo -u nagios sh -c "cd /tmp ; $command" )
eval CODE='$'EXIT_CODE_COLOR_$?
if [ -t 1 ]; then
printf "\033[37;1;4%dm%s\033[0m - %s\n" "$CODE" "$check" "${result%%|*}"
else
printf "%s - %s\n" "$check" "${result%%|*}"
fi
fi
done