Last active
January 2, 2016 19:39
-
-
Save andineck/8351537 to your computer and use it in GitHub Desktop.
snmp
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# manual | |
http://wiki.ubuntuusers.de/SNMP | |
# install | |
# http://l3net.wordpress.com/2013/05/12/installing-net-snmp-mibs-on-ubuntu-and-debian/ | |
sudo apt-get install snmp snmpd | |
sudo nano /etc/snmp/snmp.conf | |
# comment out this line | |
> # mibs : | |
sudo nano /etc/snmp/snmptrapd.conf | |
# folgende Zeile einfügen | |
> disableAuthorization yes | |
# configure firewall | |
http://www.cyberciti.biz/faq/debain-ubuntu-install-net-snmpd-server/ | |
# configure snmp | |
sudo nano /etc/snmp/snmptrapd.conf | |
> authCommunity log,execute,net public | |
# receive traps nd log to Std out | |
sudo snmptrapd -f -Lo | |
# send trap in other terminal | |
snmptrap -v 1 -c public localhost "" "" 1 0 "" | |
# edit and restart snmpd | |
sudo nano /etc/default/snmpd | |
/etc/init.d/snmpd restart | |
# oder | |
sudo service snmpd restart | |
# watch syslog (or messages) for errors while restarting | |
tail -F /var/log/syslog | |
### add startup service | |
#! /bin/sh | |
# /etc/init.d/blah | |
# | |
# Some things that run always | |
touch /var/lock/blah | |
# Carry out specific functions when asked to by the system | |
case "$1" in | |
start) | |
echo "Starting script blah " | |
echo "Could do more here" | |
;; | |
stop) | |
echo "Stopping script blah" | |
echo "Could do more here" | |
;; | |
*) | |
echo "Usage: /etc/init.d/blah {start|stop}" | |
exit 1 | |
;; | |
esac | |
exit 0 | |
# make it executable | |
chmod 755 /etc/init.d/blah | |
### see also: http://www.bitbull.ch/wiki/index.php/Configure_snmp_trap_sending | |
### end startup service | |
# sudo nano /etc/snmp/snmpd.conf | |
> proc <process> | |
sudo service snmpd restart | |
# watch the following table for the proc entries (0..n) in the order of proc calls in snmpd.conf | |
UCD-SNMP-MIB::prTable | |
How to enable SNMP Monitoring on Ubuntu Server 12.04.2 | |
Install SNMPD | |
$ sudo apt-get install snmpd | |
Create a backup file of snmpd.conf original file that we will edit later | |
$ sudo mv /etc/snmp/snmpd.conf /etc/snmp/snmpd.conf.ori | |
Create the new snmpd.conf file | |
$ sudo vim /etc/snmp/snmpd.conf | |
Add the file with these lines | |
rocommunity public | |
syslocation "Your Location" | |
syscontact admin@domain.com | |
Then edit the /etc/default/snmpd file | |
$ sudo vim /etc/default/snmpd | |
Disable this line below by adding # in front of the line | |
#SNMPDOPTS='-Lsd -Lf /dev/null -u snmp -g snmp -I -smux -p /var/run/snmpd.pid' | |
And add a new line | |
SNMPDOPTS='-Lsd -Lf /dev/null -u snmp -I -smux -p /var/run/snmpd.pid -c /etc/snmp/snmpd.conf' | |
Restart the SNMPD service | |
$ sudo /etc/init.d/snmpd restart | |
* Restarting network management services | |
Then you're done! | |
########## | |
This mentions: | |
If you have downloaded MIBs (e.g. using snmp-mibs-downloader) I suggest to comment the following line in /etc/default/snmpd: | |
export MIBS=/usr/share/snmp/mibs | |
But it seems you need to do this also for LM-SENSORS-MIB. | |
However for Ubuntu you need to set the following line in /etc/default/snmpd: | |
export MIBS=/usr/share/mibs/netsnmp | |
######### | |
# add process supervision script | |
sudo touch /usr/local/bin/checkvdserver | |
sudo chmod +x /usr/local/bin/checkvdserver | |
sudo nano /usr/local/bin/checkvdserver | |
# paste this: | |
##################### begin file | |
#!/bin/bash | |
######################################################### | |
# Copyright Siemens AG Schweiz 2014 # | |
# # | |
# Purpose: Process supervision with SNMP Traps # | |
# Author: A. Neck # | |
# Date: 27.1.2014 # | |
######################################################### | |
# Description: | |
# This script checks whether the required processes are running. | |
# SNMP Traps are sent, when the state changes, or in the specified interval in the bad case. | |
# read variable (stored in shared memory between script calls) | |
read count < /dev/shm/checkvdserver_count | |
# initialize variable if not set with 1 | |
# 0: running, [1..interval]: not running, interval: sending trap while not running | |
count=${count:-1} | |
# interval for sending traps when at least 1 process is not running. | |
# e.g. 15 for sending every 15 min if this script is called every minute. | |
interval=15 | |
# actual number of processes | |
ps_1=$(ps -e | pgrep node | wc -l) # TODO change "node" to process name | |
ps_2=$(ps -e | pgrep node | wc -l) # TODO change "node" to process name | |
# min number of processes | |
nb_1=2 | |
nb_2=2 | |
if [ $ps_1 -ge $nb_1 ] && [ $ps_2 -ge $nb_2 ] | |
then | |
# echo running | |
if [ $count -ne 0 ] | |
then | |
count=0 | |
# UCD-SNMP-MIB::ucdStart | |
# snmptrap -v 2c -c public localhost "" .1.3.6.1.4.1.2021.251.1 | |
# IF-MIB::linkUp | |
snmptrap -v 2c -c public localhost "" .1.3.6.1.6.3.1.1.5.4 | |
fi | |
else | |
# echo not running | |
if [ $count -ge $interval ] || [ $count -eq 0 ] | |
then | |
count=1 | |
# UCD-SNMP-MIB::ucdShutdown | |
# snmptrap -v 2c -c public localhost "" .1.3.6.1.4.1.2021.251.2 | |
# IF-MIB::linkDown | |
snmptrap -v 2c -c public localhost "" .1.3.6.1.6.3.1.1.5.3 | |
else | |
((count++)) | |
fi | |
fi | |
# write variable | |
echo $count > /dev/shm/checkvdserver_count | |
################### end file | |
sudo crontab -e | |
* * * * * . /usr/local/bin/checkvdserver |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment