我使用“模板SMNP接口”来监视交换机。
它给了我这样的关键:ifOutOctets [16]
我想有一个涵盖所有端口的项目:
MaxOutOctets = max(ifOutOctets[*])
我可以在图表中使用。
我已经阅读https://www.zabbix.com/documentation/2.2/manual/config/items/itemtypes/calculated,但我似乎无法得到正确的语法。
不幸的是,你所寻求的目前是不可能的,但是有一个function要求: ZBXNEXT-1829 。 请求ZBXNEXT-1420和ZBXNEXT-1521也是相关的。
解决方法(其他人可能会发现有帮助):
#!/usr/bin/perl # This program reads off traffic from a switch by SNMP. # It compares the values with last run and returns the value of the port with the biggest change # # Usage: # snmp_max_io 192.168.1.1 # # (C) 2014-09-29 Ole Tange # License: GPLv3 my $switch = shift; my ($last,$this) = update_cache_file($switch); my %delta = delta($last,$this); my $max = max(values %delta); print "$max\n"; `logger $0 $switch returned $max`; sub delta { my ($last,$this) = @_; # IF-MIB::ifHCOutOctets.45 = Counter64: 262606806485 my %last = map { split /: /,$_ } grep /Counter/, @$last; my %this = map { split /: /,$_ } grep /Counter/, @$this; my %delta = map { $_ => undef_as_zero($this{$_}) - undef_as_zero($last{$_}) } keys %last, keys %this; return %delta; } sub undef_as_zero { my $a = shift; return $a ? $a : 0; } sub my_dump { # Returns: # ascii expression of object if Data::Dump(er) is installed # error code otherwise my @dump_this = (@_); eval "use Data::Dump qw(dump);"; if ($@) { # Data::Dump not installed eval "use Data::Dumper;"; if ($@) { my $err = "Neither Data::Dump nor Data::Dumper is installed\n". "Not dumping output\n"; print $Global::original_stderr $err; return $err; } else { return Dumper(@dump_this); } } else { # Create a dummy Data::Dump:dump as Hans Schou sometimes has # it undefined eval "sub Data::Dump:dump {}"; eval "use Data::Dump qw(dump);"; return (Data::Dump::dump(@dump_this)); } } sub update_cache_file { # Input: # $switch = DNS name or IP address of switch my $switch = shift; my $tmpdir = "/tmp/switch-$ENV{USER}"; my $tmpfile = "$tmpdir/snmp_last_$switch"; mkdir $tmpdir; chmod 0700, $tmpdir || die; my @last = `cat $tmpfile 2>/dev/null`; my @this = snmpget_io($switch); open(OUT,">",$tmpfile) || die; print OUT @this; close OUT; if(not @last) { @last = @this; } return (\@last,\@this); } sub snmpget_io { # Input: # $switch = DNS name or IP address of switch my $switch = shift; # Requires snmp-mibs-downloader installed return qx{ bash -c 'snmpget -v 2c -c public $switch IF-MIB::ifHCInOctets.{1..60}; snmpget -v 2c -c public $switch IF-MIB::ifHCOutOctets.{1..60};' } } sub max { # Returns: # Maximum value of array my $max; for (@_) { # Skip undefs defined $_ or next; defined $max or do { $max = $_; next; }; # Set $_ to the first non-undef $max = ($max > $_) ? $max : $_; } return $max; }