From 9983c2ea30b75df5dc493e48d5a95d672bbce0c3 Mon Sep 17 00:00:00 2001 From: Daniel Berteaud Date: Wed, 17 Apr 2013 15:39:57 +0200 Subject: [PATCH] Add scripts to discover network interfaces --- zabbix_conf/net_interface.conf | 2 ++ zabbix_scripts/disco_net_interface | 20 ++++++++++++++++++++ 2 files changed, 22 insertions(+) create mode 100644 zabbix_conf/net_interface.conf create mode 100644 zabbix_scripts/disco_net_interface diff --git a/zabbix_conf/net_interface.conf b/zabbix_conf/net_interface.conf new file mode 100644 index 0000000..5b6752b --- /dev/null +++ b/zabbix_conf/net_interface.conf @@ -0,0 +1,2 @@ +# Can replace the builtin net.if.discovery on agent < 2.0.0 +UserParameter=net.if.discovery,/var/lib/zabbix/bin/disco_net_interface diff --git a/zabbix_scripts/disco_net_interface b/zabbix_scripts/disco_net_interface new file mode 100644 index 0000000..d73b58d --- /dev/null +++ b/zabbix_scripts/disco_net_interface @@ -0,0 +1,20 @@ +#!/usr/bin/perl -w + +use JSON; + +opendir(my $dh, "/sys/class/net") or die "Couldn't open /sys/class/net: $!"; +my @nics = grep { $_ !~ m/^\./ } readdir($dh); +closedir($dh); +my $json; +foreach my $nic (@nics){ + # Untaint $nic and makes sure the name looks OK + next unless ($nic =~ m/^(\w+[\.:]?\d+)$/); + $nic = $1; + next if ( + # skip non links + !-l "/sys/class/net/$nic" + ); + push @{$json->{data}}, { "{#IFNAME}" => $nic}; +} +print to_json($json) if (defined $json->{data}); +exit(0);