-
Notifications
You must be signed in to change notification settings - Fork 0
/
nagios_nrpe_snmp.sh
86 lines (77 loc) · 2.6 KB
/
nagios_nrpe_snmp.sh
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
74
75
76
77
78
79
80
81
82
83
84
85
86
#!/bin/bash
## nagios nrpe snmp 2016-08-05
## http://www.aqzt.com
##email: [email protected]
##robert yu
##centos 6
cat >/usr/local/nagios/etc/nrpe.cfg<<EOF
log_facility=daemon
pid_file=/var/run/nrpe.pid
server_port=5666
nrpe_user=nagios
nrpe_group=nagios
allowed_hosts=127.0.0.1,192.168.10.112
dont_blame_nrpe=0
allow_bash_command_substitution=0
debug=0
command_timeout=60
connection_timeout=300
command[check_users]=/usr/local/nagios/libexec/check_users -w 8 -c 12
command[check_load]=/usr/local/nagios/libexec/check_load -w 15,10,5 -c 30,25,20
command[check_mem]=/usr/local/nagios/libexec/check_mem.sh -w 75 -c 85
command[check_/]=/usr/local/nagios/libexec/check_disk -w 20% -c 10% -p /
command[check_/data]=/usr/local/nagios/libexec/check_disk -w 20% -c 10% -p /data
command[check_/opt]=/usr/local/nagios/libexec/check_disk -w 20% -c 10% -p /opt
command[check_ss]=/usr/local/nagios/libexec/check_ss.sh 1000 3000
command[check_eth0]=/usr/local/nagios/libexec/check_traffic.sh -V 2c -C public -H 127.0.0.1 -N eth0 -w 5000,5000 -c 10000,10000 -K -B
command[check_eth1]=/usr/local/nagios/libexec/check_traffic.sh -V 2c -C public -H 127.0.0.1 -N eth1 -w 5000,5000 -c 10000,10000 -K -B
EOF
em1=`ip a |grep em1 | awk -F ": " '{print $2}' | head -n 1`
if [ -z "$em1" ] ; then
echo "No em1"
else
sed -i 's/eth0/em1/g' /usr/local/nagios/etc/nrpe.cfg
fi
em2=`ip a |grep em2 | awk -F ": " '{print $2}' | head -n 1`
if [ -z "$em2" ] ; then
echo "No em2"
else
sed -i 's/eth1/em2/g' /usr/local/nagios/etc/nrpe.cfg
fi
eth0=`ip a |grep eth0 | awk -F ": " '{print $2}' | head -n 1`
if [ -z "$eth0" ] ; then
echo "No eth0"
else
echo "eth0"
fi
eth1=`ip a |grep eth1 | awk -F ": " '{print $2}' | head -n 1`
if [ -z "$eth1" ] ; then
echo "No eth1"
else
echo "eth1"
fi
#############snmp#####################
cat >/etc/snmp/snmpd.conf<<EOF
com2sec notConfigUser 127.0.0.1 public
com2sec notConfigUser 192.168.10.112 public
group notConfigGroup v1 notConfigUser
group notConfigGroup v2c notConfigUser
view systemview included .1.3.6.1.2.1.1
view systemview included .1.3.6.1.2.1.2
view systemview included .1.3.6.1.2.1.25.1.1
view all included .1 80
access notConfigGroup "" any noauth exact all none none
dontLogTCPWrappersConnects yes
EOF
/sbin/service snmpd restart
chkconfig snmpd on
########################nagios############################
commande=`ps aux |grep nagios |grep nrpe | grep -v 'grep' | awk '{print $2}'`
##echo $commande
if [ -z "$commande" ] ; then
echo "No nrpe"
else
ps aux |grep nagios |grep nrpe | grep -v 'grep' | awk '{print $2}' | xargs kill
fi
/usr/local/nagios/bin/nrpe -c /usr/local/nagios/etc/nrpe.cfg -d
echo ok