From d8a5c20913d0c0e855736c4083793168b5174be5 Mon Sep 17 00:00:00 2001 From: mirko Date: Tue, 28 May 2013 10:03:03 +0000 Subject: [PATCH] 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-lua) and many userparameters (using libiwinfo-lua) zabbix-extra-mac80211: a phy (phy0) detection rule and userparameters for mac80211 devices zabbix-extra-network and zabbix-extra-wifi will work as non root user if /etc/config/wireless and /etc/config/network are world-readeable (default) (see http://nbd.name/gitweb.cgi?p=uci.git;a=commit;h=07d6fd66f6a20e35490bc8b55d26fdb389016120) zabbix-extra-mac80211 come with a suid helper 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 git-svn-id: svn://svn.openwrt.org/openwrt/packages@36740 3c298f89-4303-0410-b956-a3cf2f4a3e73 --- admin/zabbix/Makefile | 85 ++++++++++++++++++++++ admin/zabbix/files/mac80211 | 27 +++++++ admin/zabbix/files/network | 9 +++ admin/zabbix/files/wifi | 29 ++++++++ admin/zabbix/files/zabbix_helper_mac80211.c | 32 ++++++++ .../zabbix/patches/010-change-agentd-config.patch | 11 ++- 6 files changed, 191 insertions(+), 2 deletions(-) create mode 100644 admin/zabbix/files/mac80211 create mode 100644 admin/zabbix/files/network create mode 100644 admin/zabbix/files/wifi create mode 100644 admin/zabbix/files/zabbix_helper_mac80211.c diff --git a/admin/zabbix/Makefile b/admin/zabbix/Makefile index b05556797..23f9efb2d 100644 --- a/admin/zabbix/Makefile +++ b/admin/zabbix/Makefile @@ -41,6 +41,24 @@ define Package/zabbix-agentd TITLE+= agentd endef +define Package/zabbix-extra-mac80211 + $(call Package/zabbix/Default) + TITLE+= discovery/userparameters for mac80211 + DEPENDS += +zabbix-agentd @PACKAGE_MAC80211_DEBUGFS @KERNEL_DEBUG_FS +endef + +define Package/zabbix-extra-network + $(call Package/zabbix/Default) + TITLE+= discovery/userparameters for network + DEPENDS += +zabbix-agentd +libuci-lua +lua +endef + +define Package/zabbix-extra-wifi + $(call Package/zabbix/Default) + TITLE+= discovery/userparameters for wifi + DEPENDS += +zabbix-agentd +libiwinfo-lua +libuci-lua +lua +endef + define Package/zabbix-sender $(call Package/zabbix/Default) TITLE+= sender @@ -63,6 +81,25 @@ define Package/zabbix-proxy DEPENDS += +libsqlite3 endef +define Package/zabbix-extra-mac80211/description +An extra package for zabbix-agentd that adds a discovery rule for mac80211 wifi phy and many userparameters. +It contains an suid helper to allow zabbix-agentd to still run as zabbix user and not as root. +See http://wiki.openwrt.org/doc/howto/zabbix for ready to use zabbix templates. +endef + +define Package/zabbix-extra-network/description +An extra package for zabbix-agentd that adds a discovery rule for openwrt network interfaces. +The idea here is to discover only interfaces listed in /etc/config/network (discover br-lan and not eth0.1 and wlan0) +See http://wiki.openwrt.org/doc/howto/zabbix for ready to use zabbix templates. +endef + +define Package/zabbix-extra-wifi/description +An extra package for zabbix-agentd that adds a discovery rule for wifi interfaces and many userparameters. +As it uses libiwinfo, it works with all wifi devices supported by openwrt. +See http://wiki.openwrt.org/doc/howto/zabbix for ready to use zabbix templates. +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 +150,15 @@ define Package/zabbix/install/init.d $(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 @@ -126,6 +172,27 @@ define Package/zabbix-proxy/conffiles /etc/zabbix_proxy.conf endef +ifdef CONFIG_PACKAGE_zabbix-extra-mac80211 +define Build/Prepare/zabbix-extra-mac80211 + mkdir -p $(PKG_BUILD_DIR)/zabbix-extra-mac80211 + $(CP) ./files/zabbix_helper_mac80211.c $(PKG_BUILD_DIR)/zabbix-extra-mac80211/ +endef + +define Build/Compile/zabbix-extra-mac80211 + $(TARGET_CC) $(TARGET_CFLAGS) $(PKG_BUILD_DIR)/zabbix-extra-mac80211/zabbix_helper_mac80211.c -o $(PKG_BUILD_DIR)/zabbix-extra-mac80211/zabbix_helper_mac80211 +endef +endif + +define Build/Prepare + $(call Build/Prepare/Default) + $(call Build/Prepare/zabbix-extra-mac80211) +endef + +define Build/Compile + $(call Build/Compile/Default) + $(call Build/Compile/zabbix-extra-mac80211) +endef + define Package/zabbix-agent/install $(call Package/zabbix/install/sbin,$(1),agent) $(call Package/zabbix/install/etc,$(1),agent) @@ -137,6 +204,21 @@ define Package/zabbix-agentd/install $(call Package/zabbix/install/init.d,$(1),agentd) endef +define Package/zabbix-extra-mac80211/install + $(call Package/zabbix/install/zabbix.conf.d,$(1),agentd,mac80211) + $(INSTALL_DIR) $(1)/usr/bin + $(INSTALL_BIN) $(PKG_BUILD_DIR)/zabbix-extra-mac80211/zabbix_helper_mac80211 $(1)/usr/bin/ + chmod 4755 $(1)/usr/bin/zabbix_helper_mac80211 +endef + +define Package/zabbix-extra-network/install + $(call Package/zabbix/install/zabbix.conf.d,$(1),agentd,network) +endef + +define Package/zabbix-extra-wifi/install + $(call Package/zabbix/install/zabbix.conf.d,$(1),agentd,wifi) +endef + define Package/zabbix-sender/install $(call Package/zabbix/install/bin,$(1),sender) endef @@ -157,6 +239,9 @@ 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)) diff --git a/admin/zabbix/files/mac80211 b/admin/zabbix/files/mac80211 new file mode 100644 index 000000000..1e5c08641 --- /dev/null +++ b/admin/zabbix/files/mac80211 @@ -0,0 +1,27 @@ +#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) + +# mac80211 phy discovery (like 'phy0') +# exemple: {"data":[{"{#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) +# +UserParameter=mac80211.ACKFailureCount[*],zabbix_helper_mac80211 $1 dot11ACKFailureCount +UserParameter=mac80211.FCSErrorCount[*],zabbix_helper_mac80211 $1 dot11FCSErrorCount +UserParameter=mac80211.RTSFailureCount[*],zabbix_helper_mac80211 $1 dot11RTSFailureCount +UserParameter=mac80211.RTSSuccessCount[*],zabbix_helper_mac80211 $1 dot11RTSSuccessCount +UserParameter=mac80211.FailedCount[*],zabbix_helper_mac80211 $1 failed_count +UserParameter=mac80211.FrameDuplicateCount[*],zabbix_helper_mac80211 $1 frame_duplicate_count +UserParameter=mac80211.MulticastReceivedFrameCount[*],zabbix_helper_mac80211 $1 multicast_received_frame_count +UserParameter=mac80211.MulticastTransmittedFrameCount[*],zabbix_helper_mac80211 $1 multicast_transmitted_frame_count +UserParameter=mac80211.MultipleRetryCount[*],zabbix_helper_mac80211 $1 multiple_retry_count +UserParameter=mac80211.ReceivedFragmentCount[*],zabbix_helper_mac80211 $1 received_fragment_count +UserParameter=mac80211.RetryCount[*],zabbix_helper_mac80211 $1 retry_count +UserParameter=mac80211.TransmittedFragmentCount[*],zabbix_helper_mac80211 $1 transmitted_fragment_count +UserParameter=mac80211.TransmittedFrameCount[*],zabbix_helper_mac80211 $1 transmitted_frame_count + diff --git a/admin/zabbix/files/network b/admin/zabbix/files/network new file mode 100644 index 000000000..51cb1cbc2 --- /dev/null +++ b/admin/zabbix/files/network @@ -0,0 +1,9 @@ +#see http://wiki.openwrt.org/doc/howto/zabbix for ready to use templates + +# network interface discovery +# exemple: {"data":[{"{#IF}":"lo", "{#NET}":"loopback"},{"{#IF}":"br-lan", "{#NET}":"lan"},{"{#IF}":"eth0.1", "{#NET}":"wan"}]} +# +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"].."\"}," end); list=string.gsub(list,",$",""); print(list.."]}")' + + + diff --git a/admin/zabbix/files/wifi b/admin/zabbix/files/wifi new file mode 100644 index 000000000..49bb38516 --- /dev/null +++ b/admin/zabbix/files/wifi @@ -0,0 +1,29 @@ +#see http://wiki.openwrt.org/doc/howto/zabbix for ready to use templates + +# wifi interface discovery +# exemple: {"data":[{"{#IF}":"wlan0", "{#MODE}":"ap", "{#SSID}":"Openwrt", "{#NET}":"lan", "{#DEV}":"radio0", "{#ENC}":"psk2+ccmp", "{#TYPE}":"mac80211", "{#HWMODE}":"11ng", "{#CHANNEL}":"11", "{#BSSID}":"xx:xx:xx:xx:xx:xx"}]} +# +UserParameter=wifi.ifdiscovery,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.."\", \"{#MODE}\":\""..s.mode.."\", \"{#SSID}\":\""..s.ssid.."\", \"{#NET}\":\""..s.network.."\", \"{#DEV}\":\""..s.device.."\", \"{#ENC}\":\""..(s.encryption or "?").."\", \"{#TYPE}\":\""..x:get("wireless",s.device,"type").."\", \"{#HWMODE}\":\""..(x:get("wireless",s.device,"hwmode") or "?").."\", \"{#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, like 'wlan0') +UserParameter=wifi.iwinfo.channel[*],lua -l iwinfo -e "print(iwinfo[iwinfo.type('$1')].channel('$1'))" +UserParameter=wifi.iwinfo.frequency[*],lua -l iwinfo -e "print(iwinfo[iwinfo.type('$1')].frequency('$1'))" +UserParameter=wifi.iwinfo.txpower[*],lua -l iwinfo -e "print(iwinfo[iwinfo.type('$1')].txpower('$1'))" +UserParameter=wifi.iwinfo.bitrate[*],lua -l iwinfo -e "b = iwinfo[iwinfo.type('$1')].bitrate('$1'); print(b or '0')" +UserParameter=wifi.iwinfo.signal[*],lua -l iwinfo -e "s = iwinfo[iwinfo.type('$1')].signal('$1'); print(s or '-255')" +UserParameter=wifi.iwinfo.noise[*],lua -l iwinfo -e "print(iwinfo[iwinfo.type('$1')].noise('$1'))" +UserParameter=wifi.iwinfo.quality[*],lua -l iwinfo -e "print(iwinfo[iwinfo.type('$1')].quality('$1'))" +UserParameter=wifi.iwinfo.quality_max[*],lua -l iwinfo -e "print(iwinfo[iwinfo.type('$1')].quality_max('$1'))" +UserParameter=wifi.iwinfo.mode[*],lua -l iwinfo -e "print(iwinfo[iwinfo.type('$1')].mode('$1'))" +UserParameter=wifi.iwinfo.ssid[*],lua -l iwinfo -e "print(iwinfo[iwinfo.type('$1')].ssid('$1'))" +UserParameter=wifi.iwinfo.bssid[*],lua -l iwinfo -e "print(iwinfo[iwinfo.type('$1')].bssid('$1'))" +UserParameter=wifi.iwinfo.country[*],lua -l iwinfo -e "print(iwinfo[iwinfo.type('$1')].country('$1'))" +UserParameter=wifi.iwinfo.nbusers[*],lua -l iwinfo -e "n = 0; for _,_ in pairs(iwinfo[iwinfo.type('$1')].assoclist('$1')) do n = n + 1 end; print(n)" +UserParameter=wifi.iwinfo.encryption[*],lua -l iwinfo -e "e = iwinfo[iwinfo.type('$1')].encryption('$1'); print(e and e.description or 'None')" +UserParameter=wifi.iwinfo.hwmode[*],lua -l iwinfo -e "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 ''))" + +#uci info (you need {#DEV} as parameter, like 'radio0') +UserParameter=wifi.uci.hwmode[*],lua -l uci -e "x = uci.cursor(nil, '/var/state'); print(x:get('wireless','$1','hwmode'))" +UserParameter=wifi.uci.channel[*],lua -l uci -e "x = uci.cursor(nil, '/var/state'); print(x:get('wireless','$1','channel'))" +UserParameter=wifi.uci.txpower[*],lua -l uci -e "x = uci.cursor(nil, '/var/state'); print(x:get('wireless','$1','txpower'))" diff --git a/admin/zabbix/files/zabbix_helper_mac80211.c b/admin/zabbix/files/zabbix_helper_mac80211.c new file mode 100644 index 000000000..cb6d622cc --- /dev/null +++ b/admin/zabbix/files/zabbix_helper_mac80211.c @@ -0,0 +1,32 @@ +#define _GNU_SOURCE +#include +#include +#include + +int main(int argc, char *argv[]) { + + if(argc == 3) { + char *phy = NULL; + char *stat = NULL; + char *filename = NULL; + FILE *f = NULL; + phy = basename(argv[1]); + stat = basename(argv[2]); + if(asprintf(&filename, "/sys/kernel/debug/ieee80211/%s/statistics/%s", phy, stat) > 0) + f = fopen(filename, "r"); + + if(f != NULL) { + char temp[256]; + while (fgets(temp, 256, f) != NULL) + printf("%s",temp); + + fclose(f); + } + free(filename); + } else { + fprintf(stderr, "Usage: %s PHY STAT\n",argv[0]); + fprintf(stderr, " cat /sys/kernel/debug/ieee80211/PHY/statistics/STAT as root\n"); + return 1; + } + return 0; +} diff --git a/admin/zabbix/patches/010-change-agentd-config.patch b/admin/zabbix/patches/010-change-agentd-config.patch index bff3b0416..58424e9ac 100644 --- a/admin/zabbix/patches/010-change-agentd-config.patch +++ b/admin/zabbix/patches/010-change-agentd-config.patch @@ -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 @@ index ed04751..e714c4d 100644 ### 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 ####### + -- 2.11.0