-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathlibrenms.sh
executable file
·148 lines (131 loc) · 5.02 KB
/
librenms.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
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
#!/usr/bin/env bash
set -e
# LibreNMS client installation
if [ "${EUID}" -ne 0 ]; then
echo "This script should be run as root."
exit 1
fi
if [ "$#" -ne 1 ]; then
echo "Plase give the LibreNMS server IP as the only parameter."
exit 1
fi
apt-get update
if ! command -v wget &> /dev/null; then
echo "Wget was not found. Installing it now."
apt-get install wget -y
fi
if ! [ -f /etc/snmp/snmpd.conf ]; then
echo "SNMP installation was not found. Installing it now."
apt-get install snmpd -y
fi
if command -v ufw &> /dev/null; then
echo "Creating firewall rule for SNMP"
ufw allow from "$1" to any port snmp comment "LibreNMS SNMP"
echo "Creating firewall rule for check_mk"
ufw allow from "$1" to any port 6556 comment "LibreNMS check_mk"
else
echo "Could not create firewall rules, as ufw was not found."
fi
# check_mk agent
# https://docs.librenms.org/Extensions/Agent-Setup/
echo "Downloading check_mk agent"
if [ -d /opt/librenms-agent ]; then
echo "LibreNMS agent appears to be already downloaded. If you have run this script previously, check afterwards that there are no duplicate lines in /etc/snmp/snmpd.conf."
cd /opt/librenms-agent
git pull
else
cd /opt/
git clone https://github.com/librenms/librenms-agent.git
cd /opt/librenms-agent
fi
echo "Installing check_mk agent"
cp check_mk_agent /usr/bin/check_mk_agent
chown root:root /usr/bin/check_mk_agent
chmod 755 /usr/bin/check_mk_agent
cp check_mk@.service check_mk.socket /etc/systemd/system/
mkdir -p /usr/lib/check_mk_agent/plugins /usr/lib/check_mk_agent/local
# dmi
echo "Installing check_mk dmi"
cp /opt/librenms-agent/agent-local/dmi /usr/lib/check_mk_agent/local/
chown root:root /usr/lib/check_mk_agent/local/dmi
chmod 755 /usr/lib/check_mk_agent/local/dmi
# dpkg
echo "Installing check_mk dpkg"
cp /opt/librenms-agent/agent-local/dpkg /usr/lib/check_mk_agent/local/
chown root:root /usr/lib/check_mk_agent/local/dpkg
chmod 755 /usr/lib/check_mk_agent/local/dpkg
echo "Enabling check_mk service"
systemctl enable check_mk.socket
systemctl start check_mk.socket
# SNMP extend
echo "Installing SNMP extensions"
# Entropy
echo "Installing entropy support"
wget https://raw.githubusercontent.com/librenms/librenms-agent/master/snmp/entropy.sh -O /etc/snmp/entropy.sh
chown root:root /etc/snmp/entropy.sh
chmod 755 /etc/snmp/entropy.sh
echo "extend entropy /etc/snmp/entropy.sh" >> /etc/snmp/snmpd.conf
# Nvidia
if command -v nvidia-smi &> /dev/null; then
echo "Nvidia driver found. Installing Nvidia GPU support."
wget https://github.com/librenms/librenms-agent/raw/master/snmp/nvidia -O /etc/snmp/nvidia
chown root:root /etc/snmp/nvidia
chmod 755 /etc/snmp/nvidia
echo "extend nvidia /etc/snmp/nvidia" >> /etc/snmp/snmpd.conf
fi
# OS Updates
echo "Installing OS update support"
wget https://raw.githubusercontent.com/librenms/librenms-agent/master/snmp/osupdate -O /etc/snmp/osupdate
chown root:root /etc/snmp/osupdate
chmod 755 /etc/snmp/osupdate
echo "extend osupdate /etc/snmp/osupdate" >> /etc/snmp/snmpd.conf
# Raspberry Pi
if [ -f /proc/device-tree/model ] && [[ $(cat /proc/device-tree/model) != Raspberry* ]]; then
echo "Raspberry pi detected. Installing support."
wget https://raw.githubusercontent.com/librenms/librenms-agent/master/snmp/raspberry.sh -O /etc/snmp/raspberry.sh
chown root:root /etc/snmp/raspberry.sh
chmod 755 /etc/snmp/raspberry.sh
echo "extend raspberry sudo /etc/snmp/raspberry.sh" >> /etc/snmp/snmpd.conf
echo "NOTE! Run visudo and add the following:"
echo "Debian-snmp ALL=(ALL) NOPASSWD: /etc/snmp/raspberry.sh, /usr/bin/vcgencmd"
fi
# SMART
echo "Do you want to install SMART support?"
select yn in "Yes" "No"; do
case $yn in
Yes)
INSTALL_SMART=1
break
;;
No)
INSTALL_SMART=0
break
;;
*)
echo "Please use a number for the selection"
;;
esac
done
if [ $INSTALL_SMART -eq 1 ]; then
apt-get install -y smartmontools
wget https://github.com/librenms/librenms-agent/raw/master/snmp/smart -O /etc/snmp/smart
chown root:root /etc/snmp/smart
chmod 755 /etc/snmp/smart
# The default config is not useful
# cp ./smart.config /etc/snmp/smart.config
/etc/snmp/smart -g > /etc/snmp/smart.config
echo "extend smart /etc/snmp/smart" >> /etc/snmp/snmpd.conf
echo "NOTE! Run visudo and add the following:"
echo "Debian-snmp ALL=(ALL) NOPASSWD: /etc/snmp/smart, /usr/bin/env smartctl"
echo "Also run \"sudo crontab -e\" and add the following:"
echo "*/3 * * * * /etc/snmp/smart -u"
fi
echo "Starting snmpd to see that it works."
systemctl restart snmpd
systemctl status snmpd
echo "Stopping snmpd to allow configuring."
systemctl stop snmpd
systemctl status snmpd
# https://stackoverflow.com/questions/13538307/net-snmp-reloading-working-in-strange-way
echo "Do not edit the snmpd config while it's running! You may run into bizarre issues with SNMPv3 user settings not being applied."
echo "SNMPv3 SHA-512 and AES-256 have been verified to work with LibreNMS."