net/lsm: add link state monitor package. (thank you Brian J. Murrell)

git-svn-id: svn://svn.openwrt.org/openwrt/packages@23326 3c298f89-4303-0410-b956-a3cf2f4a3e73
This commit is contained in:
acoul 2010-10-08 15:23:33 +00:00
parent d9d7e38eb6
commit 9d92247f50
4 changed files with 179 additions and 0 deletions

59
net/lsm/Makefile Normal file
View File

@ -0,0 +1,59 @@
#
# Copyright (C) 2006 OpenWrt.org
#
# This is free software, licensed under the GNU General Public License v2.
# See /LICENSE for more information.
#
include $(TOPDIR)/rules.mk
PKG_NAME:=lsm
PKG_VERSION:=0.53
PKG_RELEASE:=1
PKG_SOURCE:=$(PKG_NAME)-$(PKG_VERSION).tar.gz
PKG_SOURCE_URL:=http://lsm.foobar.fi/download
PKG_MD5SUM:=983911b434a3c649fcefdc99e6ea2f37
include $(INCLUDE_DIR)/package.mk
define Package/lsm
SECTION:=net
CATEGORY:=Network
DEPENDS:=+ssmtp
TITLE:=A link state monitor
URL:=http://lsm.foobar.fi/
endef
define Package/lsm/description
lsm is a link state monitor for carrying out actions when a link
transistions from the up to down state or vice versa.
endef
define Package/lsm/conffiles
/etc/lsm/lsm.conf
endef
define Build/Prepare
$(call Build/Prepare/Default)
rmdir $(PKG_BUILD_DIR)
mv $(BUILD_DIR)/lsm $(PKG_BUILD_DIR)
endef
define Build/Compile
echo sed -ie 's/\$$$$(CC)/mipsel-openwrt-linux-uclibc-gcc/g' $(PKG_BUILD_DIR)/Makefile
$(MAKE) -C $(PKG_BUILD_DIR) CC=$(TARGET_CC)
endef
define Package/lsm/install
$(INSTALL_DIR) $(1)/usr/sbin
$(INSTALL_BIN) $(PKG_BUILD_DIR)/lsm $(1)/usr/sbin/
$(INSTALL_DIR) $(1)/etc/lsm
$(INSTALL_DIR) $(1)/etc/lsm/script.d
$(INSTALL_DIR) $(1)/etc/init.d
$(INSTALL_DATA) ./files/lsm.conf $(1)/etc/lsm/lsm.conf
$(INSTALL_BIN) ./files/lsm_script $(1)/etc/lsm/script
$(INSTALL_BIN) ./files/lsm.init $(1)/etc/init.d/lsm
endef
$(eval $(call BuildPackage,lsm))

42
net/lsm/files/lsm.conf Normal file
View File

@ -0,0 +1,42 @@
#
# (C) 2009 Mika Ilmaranta <ilmis at nullnet.fi>
#
# License: GPLv2
#
#
# Debug level: 0 .. 8 are normal, 9 gives lots of stuff and 100 doesn't
# bother to detach
#
#debug=10
#debug=9
debug=8
#
# Defaults for the connection entries
#
defaults {
name=defaults
checkip=127.0.0.1
eventscript=/etc/lsm/script
max_packet_loss=15
max_successive_pkts_lost=7
min_packet_loss=5
min_successive_pkts_rcvd=10
interval_ms=2000
timeout_ms=2000
warn_email=root
check_arp=0
sourceip=
# if using ping probes for monitoring only then defaults should
# not define a default device for packets to autodiscover their path
# to destination
# device=eth0
# use system default ttl
ttl=0
}
include /etc/lsm/connections.conf
#EOF

12
net/lsm/files/lsm.init Normal file
View File

@ -0,0 +1,12 @@
#!/bin/sh /etc/rc.common
# Copyright (C) 2006 OpenWrt.org
START=50
start() {
lsm /etc/lsm/lsm.conf
}
stop() {
killall lsm
}

66
net/lsm/files/lsm_script Normal file
View File

@ -0,0 +1,66 @@
#!/bin/sh
#
# (C) 2009 Mika Ilmaranta <ilmis at nullnet.fi>
#
# License: GPLv2
#
#
# default event handling script
#
DATE=$(/bin/date)
STATE=${1}
NAME=${2}
CHECKIP=${3}
DEVICE=${4}
WARN_EMAIL=${5}
REPLIED=${6}
WAITING=${7}
TIMEOUT=${8}
REPLY_LATE=${9}
CONS_RCVD=${10}
CONS_WAIT=${11}
CONS_MISS=${12}
AVG_RTT=${13}
cat <<EOM | mail -s "LSM: ${NAME} ${STATE}, IP ${CHECKIP}" ${WARN_EMAIL}
Hi,
Your connection ${NAME} has changed it's state to ${STATE} at ${DATE}.
Following parameters were passed:
newstate = ${STATE}
name = ${NAME}
checkip = ${CHECKIP}
device = ${DEVICE}
warn_email = ${WARN_EMAIL}
Packet statuses:
replied = ${REPLIED} packets replied
waiting = ${WAITING} packets waiting for reply
timeout = ${TIMEOUT} packets that have timeout (= packet loss)
reply_late = ${REPLY_LATE} packets that received a reply after timeout
cons_rcvd = ${CONS_RCVD} consecutively received replies in sequence
cons_wait = ${CONS_WAIT} consecutive packets waiting for reply
cons_miss = ${CONS_MISS} consecutive packets that have timed out
avg_rtt = ${AVG_RTT} average rtt [usec], calculated from received packets
BR,
Your LSM installation
EOM
cd /etc/lsm/script.d/
for script in $(ls); do
if [ ! -x $script ]; then
continue
fi
./$script "$@"
done
exit 0;
#EOF