From fefa87ebf2b2e001a18666e0eb160cb84282f5ba Mon Sep 17 00:00:00 2001 From: Joachim Tingvold Date: Tue, 29 Mar 2016 23:57:35 +0200 Subject: TG16-config. --- examples/tg16/munin/dhcp_usage | 80 +++++++++++++++++++++++++++++ examples/tg16/munin/dhcp_usage_ipv6 | 85 +++++++++++++++++++++++++++++++ examples/tg16/munin/dhcp_usage_total | 78 ++++++++++++++++++++++++++++ examples/tg16/munin/dhcp_usage_total_ipv6 | 74 +++++++++++++++++++++++++++ 4 files changed, 317 insertions(+) create mode 100644 examples/tg16/munin/dhcp_usage create mode 100644 examples/tg16/munin/dhcp_usage_ipv6 create mode 100644 examples/tg16/munin/dhcp_usage_total create mode 100644 examples/tg16/munin/dhcp_usage_total_ipv6 (limited to 'examples/tg16/munin') diff --git a/examples/tg16/munin/dhcp_usage b/examples/tg16/munin/dhcp_usage new file mode 100644 index 0000000..f8d29a5 --- /dev/null +++ b/examples/tg16/munin/dhcp_usage @@ -0,0 +1,80 @@ +#!/usr/bin/env perl + +use strict; +use warnings; +use POSIX; + +my $dhcpd_cmd="/usr/local/bin/dhcpd-pools"; +my $dhcpd_lf="/var/lib/dhcp/dhcpd.leases"; +my $dhcpd_cf="/etc/dhcp/dhcpd.conf"; + +my @output = `$dhcpd_cmd -c $dhcpd_cf -l $dhcpd_lf`; + +my $line; +my $subnet; +my $subnet2; + +for $line (@output) { + + next if ($line =~ /^(shared net name|Ranges|name|Shared networks|Sum of all)/) or (length $line <= 1); + + if ($line =~ /([\d]+\.[\d]+\.[\d]+\.[\d]+)\s+\-\s+([\d]+\.[\d]+\.[\d]+\.[\d]+)\s+([\d]+)\s+([\d]+)\s+([\d]+\.[\d]+)/) { + + my $first_ip=$1; + my $last_ip=$2; + my $max=$3; + my $current=$4; + my $percent=ceil($5); + + my $octet; + my @octets; + + my $octet_count=0; + for $octet (@octets=(split('\.',$first_ip))) { + if ($octet_count == 3) { + $octet_count=0; + $subnet = $first_ip; + substr($subnet,-length($octet)) = ($octet-4); + $subnet =~ s/\./_/g; + + if (defined $ARGV[0] && $ARGV[0] eq "config") { + print_config($subnet); + } else { + print "dhcp_pool_${subnet}.value $percent\n"; + } + + } + + $octet_count++; + + } + + } + +} + +sub print_config { + +my $graph_name; + +$graph_name = shift; + +print <= 1 and $count <= 3) { + + #print "DEBUG: $line\n"; + + if ($line =~ /\s+([\d]+)\s+([\d]+)\s+([\d]+\.[\d]+)/) { + $max=($1-$2); + $current=$2; + $percent=ceil($3); + + if (defined $ARGV[0] && $ARGV[0] eq "config") { + print_config(); + } else { + print "dhcp_lease_total_current.value $current\n"; + print "dhcp_lease_total_current_max.value $max\n"; + } + + } +$count++; + } + +} + +sub print_config { + +print <= 1 and $count <= 3) { + + #print "DEBUG: $line\n"; + + if ($line =~ /\s+([\d]+)\s+([\d]+)\s+([\d]+\.[\d]+)/) { + $max=($1-$2); + $current=$2; + $percent=ceil($3); + + if (defined $ARGV[0] && $ARGV[0] eq "config") { + print_config(); + } else { + print "dhcp_lease_total_current.value $current\n"; + } + + } +$count++; + } + +} + +sub print_config { + +print <