Hi

This patch add 3 extra packages for zabbix-agentd:
zabbix-extra-network: a detection rule with the ifname (eth0.1) and the network 
name (wan).
zabbix-extra-wifi: an universal detection rule for wifi (using libuci) and many 
userparameters (using libiwinfo)
zabbix-extra-mac80211: a phy (phy0) detection rule and userparameters for 
mac80211 devices

With each packages come a startup script to set rights so that you can still 
run zabbix as non root user.
Ready to use templates are available here: 
http://wiki.openwrt.org/doc/howto/zabbix

Please delete files/zabbix_agentd.conf, it's an empty file.

Signed-off-by: Etienne CHAMPETIER <[email protected]>

Index: files/zabbix_extra_wifi.init
===================================================================
--- files/zabbix_extra_wifi.init    (révision 0)
+++ files/zabbix_extra_wifi.init    (révision 0)
@@ -0,0 +1,18 @@
+#!/bin/sh /etc/rc.common
+# Copyright (C) 2008-2011 OpenWrt.org
+
+START=59
+
+CONFIG=/etc/zabbix_agentd.conf
+
+start() {
+    grep -q "^AllowRoot=1" ${CONFIG} || {
+        user_exists zabbix 53 || user_add zabbix 53
+        group_exists zabbix 53 || group_add zabbix 53
+        [ -d /var/state ] && {
+            chown -R root:zabbix /var/state/
+            chmod -R g+r /var/state/
+        }
+    }
+}
+
Index: files/network
===================================================================
--- files/network    (révision 0)
+++ files/network    (révision 0)
@@ -0,0 +1,8 @@
+#tested with ath9k/zabbix 2.0.3-2.0.4/openwrt AA rc1
+#see http://wiki.openwrt.org/doc/howto/zabbix for ready to use templates
+
+#
+UserParameter=netowrt.discovery,lua -l uci -e 'x = uci.cursor(nil, 
"/var/state");list = "{\"data\":[";x:foreach("network", "interface", 
function(s) list=list.."{\"{#IF}\":\""..s.ifname.."\", 
\"{#NET}\":\""..s[".name"].."\", \"{#DEV}\":\""..s.device.."\"}," end); 
list=string.gsub(list,",$",""); print(list.."]}")'
+
+
+
Index: files/mac80211
===================================================================
--- files/mac80211    (révision 0)
+++ files/mac80211    (révision 0)
@@ -0,0 +1,26 @@
+#tested with ath9k/zabbix 2.0.3-2.0.4/openwrt AA rc1
+#see http://wiki.openwrt.org/doc/howto/zabbix for ready to use templates
+
+# If you want to know the exact meaning of an UserParameter, you can search in 
the ieee80211 standard:
+# http://standards.ieee.org/getieee802/download/802.11-2012.pdf
+# exemple: for mac80211.ACKFailureCount search for dot11ACKFailureCount (page 
2145)
+
+#automatically discover mac80211 phy (phy0 ...)
+UserParameter=mac80211.phydiscovery,for phy in $(ls 
/sys/kernel/debug/ieee80211/); do list="$list,"'{"{#PHY}":"'$phy'"}'; done; 
echo '{"data":['${list#,}']}'
+
+#phy statistics (you need #PHY as parameter)
+#by default /sys/kernel/debug/ieee80211/ files are readable by root only
+UserParameter=mac80211.ACKFailureCount[*],cat 
/sys/kernel/debug/ieee80211/$1/statistics/dot11ACKFailureCount
+UserParameter=mac80211.FCSErrorCount[*],cat 
/sys/kernel/debug/ieee80211/$1/statistics/dot11FCSErrorCount
+UserParameter=mac80211.RTSFailureCount[*],cat 
/sys/kernel/debug/ieee80211/$1/statistics/dot11RTSFailureCount
+UserParameter=mac80211.RTSSuccessCount[*],cat 
/sys/kernel/debug/ieee80211/$1/statistics/dot11RTSSuccessCount
+UserParameter=mac80211.FailedCount[*],cat 
/sys/kernel/debug/ieee80211/$1/statistics/failed_count
+UserParameter=mac80211.FrameDuplicateCount[*],cat 
/sys/kernel/debug/ieee80211/$1/statistics/frame_duplicate_count
+UserParameter=mac80211.MulticastReceivedFrameCount[*],cat 
/sys/kernel/debug/ieee80211/$1/statistics/multicast_received_frame_count
+UserParameter=mac80211.MulticastTransmittedFrameCount[*],cat 
/sys/kernel/debug/ieee80211/$1/statistics/multicast_transmitted_frame_count
+UserParameter=mac80211.MultipleRetryCount[*],cat 
/sys/kernel/debug/ieee80211/$1/statistics/multiple_retry_count
+UserParameter=mac80211.ReceivedFragmentCount[*],cat 
/sys/kernel/debug/ieee80211/$1/statistics/received_fragment_count
+UserParameter=mac80211.RetryCount[*],cat 
/sys/kernel/debug/ieee80211/$1/statistics/retry_count
+UserParameter=mac80211.TransmittedFragmentCount[*],cat 
/sys/kernel/debug/ieee80211/$1/statistics/transmitted_fragment_count
+UserParameter=mac80211.TransmittedFrameCount[*],cat 
/sys/kernel/debug/ieee80211/$1/statistics/transmitted_frame_count
+
Index: files/zabbix_extra_network.init
===================================================================
--- files/zabbix_extra_network.init    (révision 0)
+++ files/zabbix_extra_network.init    (révision 0)
@@ -0,0 +1,18 @@
+#!/bin/sh /etc/rc.common
+# Copyright (C) 2008-2011 OpenWrt.org
+
+START=59
+
+CONFIG=/etc/zabbix_agentd.conf
+
+start() {
+    grep -q "^AllowRoot=1" ${CONFIG} || {
+        user_exists zabbix 53 || user_add zabbix 53
+        group_exists zabbix 53 || group_add zabbix 53
+        [ -d /var/state ] && {
+            chown -R root:zabbix /var/state/
+            chmod -R g+r /var/state/
+        }
+    }
+}
+
Index: files/wifi
===================================================================
--- files/wifi    (révision 0)
+++ files/wifi    (révision 0)
@@ -0,0 +1,23 @@
+#tested with ath9k/zabbix 2.0.3-2.0.4/openwrt AA rc1
+#see http://wiki.openwrt.org/doc/howto/zabbix for ready to use templates
+
+#
+UserParameter=wifi.discovery,lua -l uci -l iwinfo -e 'x = uci.cursor(nil, 
"/var/state");list = "{\"data\":[";x:foreach("wireless", "wifi-iface", 
function(s) list=list.."{\"{#IF}\":\""..s.ifname.."\", 
\"{#SSID}\":\""..s.ssid.."\", \"{#NET}\":\""..s.network.."\", 
\"{#DEV}\":\""..s.device.."\", 
\"{#TYPE}\":\""..x:get("wireless",s.device,"type").."\", 
\"{#PHY}\":\""..x:get("wireless",s.device,"phy").."\", 
\"{#HWMODE}\":\""..x:get("wireless",s.device,"hwmode").."\", 
\"{#CHANNEL}\":\""..x:get("wireless",s.device,"channel").."\", 
\"{#BSSID}\":\""..iwinfo[iwinfo.type(s.ifname)].bssid(s.ifname).."\"}," end); 
list=string.gsub(list,",$",""); print(list.."]}")'
+
+
+#iwinfo info (you need #IF as parameter)
+UserParameter=iwinfo.channel[*],lua -l iwinfo -e 
"print(iwinfo[iwinfo.type('$1')].channel('$1'))"
+UserParameter=iwinfo.frequency[*],lua -l iwinfo -e 
"print(iwinfo[iwinfo.type('$1')].frequency('$1'))"
+UserParameter=iwinfo.txpower[*],lua -l iwinfo -e 
"print(iwinfo[iwinfo.type('$1')].txpower('$1'))"
+UserParameter=iwinfo.bitrate[*],lua -l iwinfo -e "local b = 
iwinfo[iwinfo.type('$1')].bitrate('$1'); print(b or '0')"
+UserParameter=iwinfo.signal[*],lua -l iwinfo -e "local s = 
iwinfo[iwinfo.type('$1')].signal('$1'); print(s or '-255')"
+UserParameter=iwinfo.noise[*],lua -l iwinfo -e 
"print(iwinfo[iwinfo.type('$1')].noise('$1'))"
+UserParameter=iwinfo.quality[*],lua -l iwinfo -e 
"print(iwinfo[iwinfo.type('$1')].quality('$1'))"
+UserParameter=iwinfo.quality_max[*],lua -l iwinfo -e 
"print(iwinfo[iwinfo.type('$1')].quality_max('$1'))"
+UserParameter=iwinfo.mode[*],lua -l iwinfo -e 
"print(iwinfo[iwinfo.type('$1')].mode('$1'))"
+UserParameter=iwinfo.ssid[*],lua -l iwinfo -e 
"print(iwinfo[iwinfo.type('$1')].ssid('$1'))"
+UserParameter=iwinfo.bssid[*],lua -l iwinfo -e 
"print(iwinfo[iwinfo.type('$1')].bssid('$1'))"
+UserParameter=iwinfo.country[*],lua -l iwinfo -e 
"print(iwinfo[iwinfo.type('$1')].country('$1'))"
+UserParameter=iwinfo.nbusers[*],lua -l iwinfo -e 
"print(#iwinfo[iwinfo.type('$1')].assoclist('$1'))"
+UserParameter=iwinfo.encryption[*],lua -l iwinfo -e "local e = 
iwinfo[iwinfo.type('$1')].encryption('$1'); print(e and e.description or 
'None')"
+UserParameter=iwinfo.hwmode[*],lua -l iwinfo -e "local 
x=iwinfo[iwinfo.type('$1')].hwmodelist('$1'); print((x.a and 'a' or '')..(x.b 
and 'b' or '')..(x.g and 'g' or '')..(x.n and 'n' or ''))"
Index: files/zabbix_extra_mac80211.init
===================================================================
--- files/zabbix_extra_mac80211.init    (révision 0)
+++ files/zabbix_extra_mac80211.init    (révision 0)
@@ -0,0 +1,18 @@
+#!/bin/sh /etc/rc.common
+# Copyright (C) 2008-2011 OpenWrt.org
+
+START=59
+
+CONFIG=/etc/zabbix_agentd.conf
+
+start() {
+    grep -q "^AllowRoot=1" ${CONFIG} || {
+        user_exists zabbix 53 || user_add zabbix 53
+        group_exists zabbix 53 || group_add zabbix 53
+        [ -d /sys/kernel/debug/ieee80211 ] && {
+            chown -R root:zabbix /sys/kernel/debug/ieee80211/
+            chmod -R g+r /sys/kernel/debug/ieee80211/
+        }
+    }
+}
+
Index: patches/010-change-agentd-config.patch
===================================================================
--- patches/010-change-agentd-config.patch    (révision 34787)
+++ patches/010-change-agentd-config.patch    (copie de travail)
@@ -1,5 +1,3 @@
-diff --git a/conf/zabbix_agentd.conf b/conf/zabbix_agentd.conf
-index ed04751..e714c4d 100644
 --- a/conf/zabbix_agentd.conf
 +++ b/conf/zabbix_agentd.conf
 @@ -3,12 +3,8 @@
@@ -52,3 +50,12 @@
  ### Option: HostnameItem
  #    Item used for generating Hostname if it is undefined.
  #    Ignored if Hostname is defined.
+@@ -213,7 +204,7 @@ Hostname=Zabbix server
+ # Include=
+
+ # Include=/usr/local/etc/zabbix_agentd.userparams.conf
+-# Include=/usr/local/etc/zabbix_agentd.conf.d/
++Include=/etc/zabbix_agentd.conf.d/
+
+ ####### USER-DEFINED MONITORED PARAMETERS #######
+
Index: Makefile
===================================================================
--- Makefile    (révision 34787)
+++ Makefile    (copie de travail)
@@ -9,7 +9,7 @@
 
 PKG_NAME:=zabbix
 PKG_VERSION:=2.0.3
-PKG_RELEASE:=1
+PKG_RELEASE:=2
 
 PKG_SOURCE:=$(PKG_NAME)-$(PKG_VERSION).tar.gz
 PKG_SOURCE_URL:=@SF/zabbix
@@ -41,6 +41,24 @@
   TITLE+= agentd
 endef
 
+define Package/zabbix-extra-mac80211
+  $(call Package/zabbix/Default)
+  TITLE+= discovery/userparameters for mac80211
+  DEPENDS += +zabbix-agentd @PACKAGE_MAC80211_DEBUGFS
+endef
+
+define Package/zabbix-extra-network
+  $(call Package/zabbix/Default)
+  TITLE+= discovery/userparameters for network
+  DEPENDS += +zabbix-agentd +libuci-lua
+endef
+
+define Package/zabbix-extra-wifi
+  $(call Package/zabbix/Default)
+  TITLE+= discovery/userparameters for wifi
+  DEPENDS += +zabbix-agentd +libiwinfo-lua +libuci-lua
+endef
+
 define Package/zabbix-sender
   $(call Package/zabbix/Default)
   TITLE+= sender
@@ -63,6 +81,7 @@
   DEPENDS += +libsqlite3
 endef
 
+
 define Package/zabbix-agentd/config
   select BUSYBOX_CONFIG_HOSTNAME if !PACKAGE_net-tools-hostname
   select BUSYBOX_CONFIG_UNAME if !PACKAGE_coreutils-uname
@@ -113,6 +132,15 @@
         $(1)/etc/init.d/zabbix_$(2)
 endef
 
+define Package/zabbix/install/zabbix.conf.d
+    $(INSTALL_DIR) \
+        $(1)/etc/zabbix_$(2).conf.d
+
+    $(INSTALL_BIN) \
+        ./files/$(3) \
+        $(1)/etc/zabbix_$(2).conf.d/$(3)
+endef
+
 define Package/zabbix-agent/conffiles
 /etc/zabbix_agent.conf
 endef
@@ -137,6 +165,21 @@
     $(call Package/zabbix/install/init.d,$(1),agentd)
 endef
 
+define Package/zabbix-extra-mac80211/install
+    $(call Package/zabbix/install/init.d,$(1),extra_mac80211)
+    $(call Package/zabbix/install/zabbix.conf.d,$(1),agentd,mac80211)
+endef
+
+define Package/zabbix-extra-network/install
+    $(call Package/zabbix/install/init.d,$(1),extra_network)
+    $(call Package/zabbix/install/zabbix.conf.d,$(1),agentd,network)
+endef
+
+define Package/zabbix-extra-wifi/install
+    $(call Package/zabbix/install/init.d,$(1),extra_wifi)
+    $(call Package/zabbix/install/zabbix.conf.d,$(1),agentd,wifi)
+endef
+
 define Package/zabbix-sender/install
     $(call Package/zabbix/install/bin,$(1),sender)
 endef
@@ -155,8 +198,26 @@
     $(call Package/zabbix/install/etc,$(1),proxy)
 endef
 
+define Package/zabbix-extra-mac80211/postinst
+[ -n "$${IPKG_INSTROOT}" ] || /etc/init.d/zabbix_extra_mac80211 enable
+exit 0
+endef
+
+define Package/zabbix-extra-network/postinst
+[ -n "$${IPKG_INSTROOT}" ] || /etc/init.d/zabbix_extra_network enable
+exit 0
+endef
+
+define Package/zabbix-extra-wifi/postinst
+[ -n "$${IPKG_INSTROOT}" ] || /etc/init.d/zabbix_extra_wifi enable
+exit 0
+endef
+
 $(eval $(call BuildPackage,zabbix-agent))
 $(eval $(call BuildPackage,zabbix-agentd))
+$(eval $(call BuildPackage,zabbix-extra-mac80211))
+$(eval $(call BuildPackage,zabbix-extra-network))
+$(eval $(call BuildPackage,zabbix-extra-wifi))
 $(eval $(call BuildPackage,zabbix-sender))
 $(eval $(call BuildPackage,zabbix-server))
 $(eval $(call BuildPackage,zabbix-proxy))
_______________________________________________
openwrt-devel mailing list
[email protected]
https://lists.openwrt.org/mailman/listinfo/openwrt-devel

Reply via email to