/
plugin_wrapper
73 lines (61 loc) · 1.18 KB
/
plugin_wrapper
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
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
#!/bin/bash
# Get Arugments
while getopts a:p:s:H:hd option; do
case $option in
a) args=$OPTARG;;
p) plugin=$OPTARG;;
s) service=$OPTARG;;
H) host=$OPTARG;;
h) help=true;;
d) debug=true;;
\?)
echo "Invalid option: -$OPTARG" >&2
exit 2;;
esac
done
# Check args
if [[ ! $args ]]
then
echo 'No arguments specified'
exit 2
fi
if [[ ! $plugin ]]
then
echo 'No plugin specified'
exit 2
fi
if [[ ! $service ]]
then
echo 'No service checks specified'
exit 2
fi
# Help
if [[ $help == true ]]
then
echo "Usage: ./plugin_wrapper -a '[All arugments for plugin here]' -p [Plugin] -s [Service Check] -H [hostname]"
exit
fi
# Debug Mode:
if [[ $debug == true ]]
then
echo ''
echo 'Plugin: ' $plugin
echo 'Arguments: ' $args
echo ''
echo 'Service check: ' $service
fi
# Get output of command
cmd="/usr/local/nagios/libexec/$plugin $args"
msg=$(eval $cmd)
exitCode=$?
#More debuging
if [[ $debug == true ]]
then
echo ''
echo 'Command: ' $cmd
echo 'Command Output: ' $msg
echo 'Exit Code: ' $exitCode
echo ''
fi
# Send data to check
echo ['date+%s'] "PROCESS_SERVICE_CHECK_RESULT;$host;$service;$exitCode;$msg" > /usr/local/nagios/var/rw/nagios.cmd