/check_nwc_health
Perl | 8210 lines | 7207 code | 735 blank | 268 comment | 541 complexity | c44bbd95e4109065b20a9f1f133f9323 MD5 | raw file
Possible License(s): GPL-3.0
Large files files are truncated, but you can click here to view the full file
- #! /usr/bin/perl -w
- package Nagios::MiniPlugin;
- use strict;
- use Getopt::Long qw(:config no_ignore_case bundling);
- our @STATUS_CODES = qw(OK WARNING CRITICAL UNKNOWN DEPENDENT);
- require Exporter;
- our @ISA = qw(Exporter);
- our @EXPORT = (@STATUS_CODES, qw(nagios_exit nagios_die check_messages));
- our @EXPORT_OK = qw(%ERRORS);
- use constant OK => 0;
- use constant WARNING => 1;
- use constant CRITICAL => 2;
- use constant UNKNOWN => 3;
- use constant DEPENDENT => 4;
- our %ERRORS = (
- 'OK' => OK,
- 'WARNING' => WARNING,
- 'CRITICAL' => CRITICAL,
- 'UNKNOWN' => UNKNOWN,
- 'DEPENDENT' => DEPENDENT,
- );
- our %STATUS_TEXT = reverse %ERRORS;
- sub new {
- my $class = shift;
- my %params = @_;
- my $self = {
- perfdata => [],
- messages => {
- ok => [],
- warning => [],
- critical => [],
- unknown => [],
- },
- args => [],
- opts => Nagios::MiniPlugin::Getopt->new(%params),
- };
- foreach (qw(shortname usage version url plugin blurb extra
- license timeout)) {
- $self->{$_} = $params{$_};
- }
- bless $self, $class;
- }
- sub add_arg {
- my $self = shift;
- $self->{opts}->add_arg(@_);
- }
- sub getopts {
- my $self = shift;
- $self->{opts}->getopts();
- }
- sub override_opt {
- my $self = shift;
- $self->{opts}->override_opt(@_);
- }
- sub opts {
- my $self = shift;
- return $self->{opts};
- }
- sub add_message {
- my $self = shift;
- my ($code, @messages) = @_;
- $code = (qw(ok warning critical unknown))[$code] if $code =~ /^\d+$/;
- $code = lc $code;
- push @{$self->{messages}->{$code}}, @messages;
- }
- sub add_perfdata {
- my ($self, %args) = @_;
- #if ($args{label} =~ /\s/) {
- $args{label} = '\''.$args{label}.'\'';
- #}
- if (! exists $args{places}) {
- $args{places} = 2;
- }
- my $format = '%d';
- if ($args{value} =~ /\./) {
- $format = '%.'.$args{places}.'f';
- }
- my $str = $args{label}.'='.sprintf $format, $args{value};
- if ($args{uom}) {
- $str .= $args{uom};
- }
- if ($args{warning}) {
- $str .= ';'.$args{warning};
- }
- if ($args{critical}) {
- $str .= ';'.$args{critical};
- }
- push @{$self->{perfdata}}, $str;
- }
- sub clear_messages {
- my $self = shift;
- my $code = shift;
- $code = (qw(ok warning critical unknown))[$code] if $code =~ /^\d+$/;
- $code = lc $code;
- $self->{messages}->{$code} = [];
- }
- sub check_messages {
- my $self = shift;
- my %args = @_;
- # Add object messages to any passed in as args
- for my $code (qw(critical warning unknown ok)) {
- my $messages = $self->{messages}->{$code} || [];
- if ($args{$code}) {
- unless (ref $args{$code} eq 'ARRAY') {
- if ($code eq 'ok') {
- $args{$code} = [ $args{$code} ];
- }
- }
- push @{$args{$code}}, @$messages;
- } else {
- $args{$code} = $messages;
- }
- }
- my %arg = %args;
- $arg{join} = ' ' unless defined $arg{join};
- # Decide $code
- my $code = OK;
- $code ||= CRITICAL if @{$arg{critical}};
- $code ||= WARNING if @{$arg{warning}};
- $code ||= UNKNOWN if @{$arg{unknown}};
- return $code unless wantarray;
- # Compose message
- my $message = '';
- if ($arg{join_all}) {
- $message = join( $arg{join_all},
- map { @$_ ? join( $arg{'join'}, @$_) : () }
- $arg{critical},
- $arg{warning},
- $arg{unknown},
- $arg{ok} ? (ref $arg{ok} ? $arg{ok} : [ $arg{ok} ]) : []
- );
- }
- else {
- $message ||= join( $arg{'join'}, @{$arg{critical}} )
- if $code == CRITICAL;
- $message ||= join( $arg{'join'}, @{$arg{warning}} )
- if $code == WARNING;
- $message ||= join( $arg{'join'}, @{$arg{unknown}} )
- if $code == UNKNOWN;
- $message ||= ref $arg{ok} ? join( $arg{'join'}, @{$arg{ok}} ) : $arg{ok}
- if $arg{ok};
- }
- return ($code, $message);
- }
- sub nagios_exit {
- my $self = shift;
- my ($code, $message, $arg) = @_;
- $code = $ERRORS{$code} if defined $code && exists $ERRORS{$code};
- $code = UNKNOWN unless defined $code && exists $STATUS_TEXT{$code};
- $message = '' unless defined $message;
- if (ref $message && ref $message eq 'ARRAY') {
- $message = join(' ', map { chomp; $_ } @$message);
- } else {
- chomp $message;
- }
- my $output = "$STATUS_TEXT{$code}";
- $output .= " - $message" if defined $message && $message ne '';
- if (scalar (@{$self->{perfdata}})) {
- $output .= " | ".join(" ", @{$self->{perfdata}});
- }
- $output .= "\n";
- print $output;
- exit $code;
- }
- sub set_thresholds {
- my $self = shift;
- my %params = @_;
- $self->{mywarning} = $self->opts->warning || $params{warning} || 0;
- $self->{mycritical} = $self->opts->critical || $params{critical} || 0;
- }
- sub get_thresholds {
- my $self = shift;
- return ($self->{mywarning}, $self->{mycritical});
- }
- sub check_thresholds {
- my $self = shift;
- my @params = @_;
- my $level = $ERRORS{OK};
- my $warningrange;
- my $criticalrange;
- my $value;
- if (scalar(@params) > 1) {
- my %params = @params;
- $value = $params{check};
- $warningrange = (defined $params{warning}) ?
- $params{warning} : $self->{mywarning};
- $criticalrange = (defined $params{critical}) ?
- $params{critical} : $self->{mycritical};
- } else {
- $value = $params[0];
- $warningrange = $self->{mywarning};
- $criticalrange = $self->{mycritical};
- }
- if ($warningrange !~ /:/ && $criticalrange !~ /:/) {
- # warning = 10, critical = 20, warn if > 10, crit if > 20
- $level = $ERRORS{WARNING} if $value > $warningrange;
- $level = $ERRORS{CRITICAL} if $value > $criticalrange;
- } elsif ($warningrange =~ /(\d+):/ &&
- $criticalrange =~ /(\d+):/) {
- # warning = 98:, critical = 95:, warn if < 98, crit if < 95
- $warningrange =~ /(\d+):/;
- $level = $ERRORS{WARNING} if $value < $1;
- $criticalrange =~ /(\d+):/;
- $level = $ERRORS{CRITICAL} if $value < $1;
- }
- return $level;
- #
- # syntax error must be reported with returncode -1
- #
- }
- package Nagios::MiniPlugin::Getopt;
- use strict;
- use File::Basename;
- use Data::Dumper;
- use Getopt::Long qw(:config no_ignore_case bundling);
- # Standard defaults
- my %DEFAULT = (
- timeout => 15,
- verbose => 0,
- license =>
- "This nagios plugin is free software, and comes with ABSOLUTELY NO WARRANTY.
- It may be used, redistributed and/or modified under the terms of the GNU
- General Public Licence (see http://www.fsf.org/licensing/licenses/gpl.txt).",
- );
- # Standard arguments
- my @ARGS = ({
- spec => 'usage|?',
- help => "-?, --usage\n Print usage information",
- }, {
- spec => 'help|h',
- help => "-h, --help\n Print detailed help screen",
- }, {
- spec => 'version|V',
- help => "-V, --version\n Print version information",
- }, {
- #spec => 'extra-opts:s@',
- #help => "--extra-opts=[<section>[@<config_file>]]\n Section and/or config_file from which to load extra options (may repeat)",
- }, {
- spec => 'timeout|t=i',
- help => sprintf("-t, --timeout=INTEGER\n Seconds before plugin times out (default: %s)", $DEFAULT{timeout}),
- default => $DEFAULT{timeout},
- }, {
- spec => 'verbose|v+',
- help => "-v, --verbose\n Show details for command-line debugging (can repeat up to 3 times)",
- default => $DEFAULT{verbose},
- },
- );
- # Standard arguments we traditionally display last in the help output
- my %DEFER_ARGS = map { $_ => 1 } qw(timeout verbose);
- sub _init
- {
- my $self = shift;
- my %params = @_;
- # Check params
- my $plugin = basename($ENV{NAGIOS_PLUGIN} || $0);
- #my %attr = validate( @_, {
- my %attr = (
- usage => 1,
- version => 0,
- url => 0,
- plugin => { default => $plugin },
- blurb => 0,
- extra => 0,
- 'extra-opts' => 0,
- license => { default => $DEFAULT{license} },
- timeout => { default => $DEFAULT{timeout} },
- );
- # Add attr to private _attr hash (except timeout)
- $self->{timeout} = delete $attr{timeout};
- $self->{_attr} = { %attr };
- foreach (keys %{$self->{_attr}}) {
- if (exists $params{$_}) {
- $self->{_attr}->{$_} = $params{$_};
- } else {
- $self->{_attr}->{$_} = $self->{_attr}->{$_}->{default}
- if ref ($self->{_attr}->{$_}) eq 'HASH' &&
- exists $self->{_attr}->{$_}->{default};
- }
- }
- # Chomp _attr values
- chomp foreach values %{$self->{_attr}};
- # Setup initial args list
- $self->{_args} = [ grep { exists $_->{spec} } @ARGS ];
- $self
- }
- sub new
- {
- my $class = shift;
- my $self = bless {}, $class;
- $self->_init(@_);
- }
- sub add_arg {
- my $self = shift;
- my %arg = @_;
- push (@{$self->{_args}}, \%arg);
- }
- sub getopts {
- my $self = shift;
- my %commandline = ();
- my @params = map { $_->{spec} } @{$self->{_args}};
- if (! GetOptions(\%commandline, @params)) {
- $self->print_help();
- exit 0;
- } else {
- no strict 'refs';
- do { $self->print_help(); exit 0; } if $commandline{help};
- do { $self->print_version(); exit 0 } if $commandline{version};
- do { $self->print_usage(); exit 0 } if $commandline{usage};
- foreach (map { $_->{spec} =~ /^([\w\-]+)/; $1; } @{$self->{_args}}) {
- my $field = $_;
- *{"$field"} = sub {
- return $self->{opts}->{$field};
- };
- }
- foreach (grep { exists $_->{default} } @{$self->{_args}}) {
- $_->{spec} =~ /^([\w\-]+)/;
- my $spec = $1;
- $self->{opts}->{$spec} = $_->{default};
- }
- foreach (keys %commandline) {
- $self->{opts}->{$_} = $commandline{$_};
- }
- }
- }
- sub override_opt {
- my $self = shift;
- my $key = shift;
- my $value = shift;
- $self->{opts}->{$key} = $value;
- }
- sub get {
- my $self = shift;
- my $opt = shift;
- return $self->{opts}->{$opt};
- }
- sub print_help {
- my $self = shift;
- $self->print_version();
- printf "\n%s\n", $self->{_attr}->{license};
- printf "\n%s\n\n", $self->{_attr}->{blurb};
- $self->print_usage();
- foreach (@{$self->{_args}}) {
- printf " %s\n", $_->{help};
- }
- exit 0;
- }
- sub print_usage {
- my $self = shift;
- printf $self->{_attr}->{usage}, $self->{_attr}->{plugin};
- print "\n";
- }
- sub print_version {
- my $self = shift;
- printf "%s %s", $self->{_attr}->{plugin}, $self->{_attr}->{version};
- printf " [%s]", $self->{_attr}->{url} if $self->{_attr}->{url};
- print "\n";
- }
- sub print_license {
- my $self = shift;
- printf "%s\n", $self->{_attr}->{license};
- print "\n";
- }
- package Server::Linux;
- use strict;
- use constant { OK => 0, WARNING => 1, CRITICAL => 2, UNKNOWN => 3 };
- our @ISA = qw(NWC::Device);
- sub init {
- my $self = shift;
- $self->{components} = {
- interface_subsystem => undef,
- };
- $self->{serial} = 'unknown';
- $self->{product} = 'unknown';
- $self->{romversion} = 'unknown';
- if (! $self->check_messages()) {
- if ($self->mode =~ /device::interfaces/) {
- $self->analyze_interface_subsystem();
- $self->check_interface_subsystem();
- }
- }
- }
- sub analyze_interface_subsystem {
- my $self = shift;
- $self->{components}->{interface_subsystem} =
- Server::Linux::Component::InterfaceSubsystem->new();
- }
- sub check_interface_subsystem {
- my $self = shift;
- $self->{components}->{interface_subsystem}->check();
- $self->{components}->{interface_subsystem}->dump()
- if $self->opts->verbose >= 2;
- }
- package Server::Linux::Component::InterfaceSubsystem;
- our @ISA = qw(Server::Linux);
- use strict;
- use constant { OK => 0, WARNING => 1, CRITICAL => 2, UNKNOWN => 3 };
- sub new {
- my $class = shift;
- my %params = @_;
- my $self = {
- interfaces => [],
- blacklisted => 0,
- info => undef,
- extendedinfo => undef,
- };
- bless $self, $class;
- $self->init(%params);
- return $self;
- }
- sub init {
- my $self = shift;
- my %params = @_;
- if ($self->mode =~ /device::interfaces::list/) {
- foreach (glob "/sys/class/net/*") {
- my $name = $_;
- $name =~ s/.*\///g;
- my $tmpif = {
- ifDescr => $name,
- };
- push(@{$self->{interfaces}},
- Server::Linux::Component::InterfaceSubsystem::Interface->new(%{$tmpif}));
- }
- } else {
- foreach (glob "/sys/class/net/*") {
- my $name = $_;
- $name =~ s/.*\///g;
- if ($self->opts->name) {
- if ($self->opts->regexp) {
- my $pattern = $self->opts->name;
- if ($name !~ /$pattern/i) {
- next;
- }
- } elsif (lc $name ne lc $self->opts->name) {
- next;
- }
- }
- my $tmpif = {
- ifDescr => $name,
- ifSpeed => (-f "/sys/class/net/$name/speed" ? do { local (@ARGV, $/) = "/sys/class/net/$name/speed"; my $x = <>; close ARGV; $x} * 1024*1024 : 1024*1024*1024),
- ifInOctets => do { local (@ARGV, $/) = "/sys/class/net/$name/statistics/rx_bytes"; my $x = <>; close ARGV; $x},
- ifInDiscards => do { local (@ARGV, $/) = "/sys/class/net/$name/statistics/rx_dropped"; my $x = <>; close ARGV; $x},
- ifInErrors => do { local (@ARGV, $/) = "/sys/class/net/$name/statistics/rx_errors"; my $x = <>; close ARGV; $x},
- ifOutOctets => do { local (@ARGV, $/) = "/sys/class/net/$name/statistics/tx_bytes"; my $x = <>; close ARGV; $x},
- ifOutDiscards => do { local (@ARGV, $/) = "/sys/class/net/$name/statistics/tx_dropped"; my $x = <>; close ARGV; $x},
- ifOutErrors => do { local (@ARGV, $/) = "/sys/class/net/$name/statistics/tx_errors"; my $x = <>; close ARGV; $x},
- };
- foreach (keys %{$tmpif}) {
- chomp($tmpif->{$_});
- }
- push(@{$self->{interfaces}},
- Server::Linux::Component::InterfaceSubsystem::Interface->new(%{$tmpif}));
- }
- }
- }
- sub check {
- my $self = shift;
- my $errorfound = 0;
- $self->add_info('checking interfaces');
- $self->blacklist('ff', '');
- if (scalar(@{$self->{interfaces}}) == 0) {
- $self->add_message(UNKNOWN, 'no interfaces');
- return;
- }
- if ($self->mode =~ /device::interfaces::list/) {
- foreach (sort {$a->{ifDescr} cmp $b->{ifDescr}} @{$self->{interfaces}}) {
- $_->list();
- }
- } else {
- if (scalar (@{$self->{interfaces}}) == 0) {
- } else {
- foreach (@{$self->{interfaces}}) {
- $_->check();
- }
- }
- }
- }
- sub dump {
- my $self = shift;
- foreach (@{$self->{interfaces}}) {
- $_->dump();
- }
- }
- package Server::Linux::Component::InterfaceSubsystem::Interface;
- our @ISA = qw(Server::Linux::Component::InterfaceSubsystem);
- use strict;
- use constant { OK => 0, WARNING => 1, CRITICAL => 2, UNKNOWN => 3 };
- sub new {
- my $class = shift;
- my %params = @_;
- my $self = {
- ifDescr => $params{ifDescr},
- ifSpeed => $params{ifSpeed},
- ifInOctets => $params{ifInOctets},
- ifInDiscards => $params{ifInDiscards},
- ifInErrors => $params{ifInErrors},
- ifOutOctets => $params{ifOutOctets},
- ifOutDiscards => $params{ifOutDiscards},
- ifOutErrors => $params{ifOutErrors},
- blacklisted => 0,
- info => undef,
- extendedinfo => undef,
- };
- foreach my $key (keys %params) {
- $self->{$key} = 0 if ! defined $params{$key};
- }
- bless $self, $class;
- $self->init();
- return $self;
- }
- sub init {
- my $self = shift;
- if ($self->mode =~ /device::interfaces::traffic/) {
- $self->valdiff({name => $self->{ifDescr}}, qw(ifInOctets ifInDiscards ifInErrors ifOutOctets ifOutDiscards ifOutErrors));
- } elsif ($self->mode =~ /device::interfaces::usage/) {
- $self->valdiff({name => $self->{ifDescr}}, qw(ifInOctets ifOutOctets));
- if ($self->{ifSpeed} == 0) {
- # vlan graffl
- $self->{inputUtilization} = 0;
- $self->{outputUtilization} = 0;
- } else {
- $self->{inputUtilization} = $self->{delta_ifInOctets} * 8 * 100 /
- ($self->{delta_timestamp} * $self->{ifSpeed});
- $self->{outputUtilization} = $self->{delta_ifOutOctets} * 8 * 100 /
- ($self->{delta_timestamp} * $self->{ifSpeed});
- }
- $self->{inputRate} = $self->{delta_ifInOctets} / $self->{delta_timestamp};
- $self->{outputRate} = $self->{delta_ifOutOctets} / $self->{delta_timestamp};
- my $factor = 1/8; # default Bits
- if ($self->opts->units) {
- if ($self->opts->units eq "GB") {
- $factor = 1024 * 1024 * 1024;
- } elsif ($self->opts->units eq "MB") {
- $factor = 1024 * 1024;
- } elsif ($self->opts->units eq "KB") {
- $factor = 1024;
- } elsif ($self->opts->units eq "GBi") {
- $factor = 1024 * 1024 * 1024 / 8;
- } elsif ($self->opts->units eq "MBi") {
- $factor = 1024 * 1024 / 8;
- } elsif ($self->opts->units eq "KBi") {
- $factor = 1024 / 8;
- } elsif ($self->opts->units eq "B") {
- $factor = 1;
- } elsif ($self->opts->units eq "Bit") {
- $factor = 1/8;
- }
- }
- $self->{inputRate} /= $factor;
- $self->{outputRate} /= $factor;
- } elsif ($self->mode =~ /device::interfaces::errors/) {
- $self->valdiff({name => $self->{ifDescr}}, qw(ifInErrors ifOutErrors ifInDiscards ifOutDiscards));
- $self->{inputErrorRate} = $self->{delta_ifInErrors}
- / $self->{delta_timestamp};
- $self->{outputErrorRate} = $self->{delta_ifOutErrors}
- / $self->{delta_timestamp};
- $self->{inputDiscardRate} = $self->{delta_ifInDiscards}
- / $self->{delta_timestamp};
- $self->{outputDiscardRate} = $self->{delta_ifOutDiscards}
- / $self->{delta_timestamp};
- $self->{inputRate} = ($self->{delta_ifInErrors} + $self->{delta_ifInDiscards})
- / $self->{delta_timestamp};
- $self->{outputRate} = ($self->{delta_ifOutErrors} + $self->{delta_ifOutDiscards})
- / $self->{delta_timestamp};
- } elsif ($self->mode =~ /device::interfaces::operstatus/) {
- }
- return $self;
- }
- sub check {
- my $self = shift;
- $self->blacklist('if', $self->{ifDescr});
- if ($self->mode =~ /device::interfaces::traffic/) {
- } elsif ($self->mode =~ /device::interfaces::usage/) {
- my $info = sprintf 'interface %s usage is in:%.2f%% (%s) out:%.2f%% (%s)',
- $self->{ifDescr},
- $self->{inputUtilization},
- sprintf("%.2f%s/s", $self->{inputRate},
- ($self->opts->units ? $self->opts->units : 'Bits')),
- $self->{outputUtilization},
- sprintf("%.2f%s/s", $self->{outputRate},
- ($self->opts->units ? $self->opts->units : 'Bits'));
- $self->add_info($info);
- $self->set_thresholds(warning => 80, critical => 90);
- my $in = $self->check_thresholds($self->{inputUtilization});
- my $out = $self->check_thresholds($self->{outputUtilization});
- my $level = ($in > $out) ? $in : ($out > $in) ? $out : $in;
- $self->add_message($level, $info);
- $self->add_perfdata(
- label => $self->{ifDescr}.'_usage_in',
- value => $self->{inputUtilization},
- uom => '%',
- warning => $self->{warning},
- critical => $self->{critical},
- );
- $self->add_perfdata(
- label => $self->{ifDescr}.'_usage_out',
- value => $self->{outputUtilization},
- uom => '%',
- warning => $self->{warning},
- critical => $self->{critical},
- );
- $self->add_perfdata(
- label => $self->{ifDescr}.'_traffic_in',
- value => $self->{inputRate},
- uom => $self->opts->units,
- );
- $self->add_perfdata(
- label => $self->{ifDescr}.'_traffic_out',
- value => $self->{outputRate},
- uom => $self->opts->units,
- );
- } elsif ($self->mode =~ /device::interfaces::errors/) {
- my $info = sprintf 'interface %s errors in:%.2f/s out:%.2f/s '.
- 'discards in:%.2f/s out:%.2f/s',
- $self->{ifDescr},
- $self->{inputErrorRate} , $self->{outputErrorRate},
- $self->{inputDiscardRate} , $self->{outputDiscardRate};
- $self->add_info($info);
- $self->set_thresholds(warning => 1, critical => 10);
- my $in = $self->check_thresholds($self->{inputRate});
- my $out = $self->check_thresholds($self->{outputRate});
- my $level = ($in > $out) ? $in : ($out > $in) ? $out : $in;
- $self->add_message($level, $info);
- $self->add_perfdata(
- label => $self->{ifDescr}.'_errors_in',
- value => $self->{inputErrorRate},
- warning => $self->{warning},
- critical => $self->{critical},
- );
- $self->add_perfdata(
- label => $self->{ifDescr}.'_errors_out',
- value => $self->{outputErrorRate},
- warning => $self->{warning},
- critical => $self->{critical},
- );
- $self->add_perfdata(
- label => $self->{ifDescr}.'_discards_in',
- value => $self->{inputDiscardRate},
- warning => $self->{warning},
- critical => $self->{critical},
- );
- $self->add_perfdata(
- label => $self->{ifDescr}.'_discards_out',
- value => $self->{outputDiscardRate},
- warning => $self->{warning},
- critical => $self->{critical},
- );
- }
- }
- sub list {
- my $self = shift;
- printf "%s\n", $self->{ifDescr};
- }
- sub dump {
- my $self = shift;
- printf "[IF_%s]\n", $self->{ifDescr};
- foreach (qw(ifDescr ifSpeed ifInOctets ifInDiscards ifInErrors ifOutOctets ifOutDiscards ifOutErrors)) {
- printf "%s: %s\n", $_, defined $self->{$_} ? $self->{$_} : 'undefined';
- }
- # printf "info: %s\n", $self->{info};
- printf "\n";
- }
- package NWC::CiscoIOS::Component::CpuSubsystem;
- our @ISA = qw(NWC::CiscoIOS);
- use strict;
- use constant { OK => 0, WARNING => 1, CRITICAL => 2, UNKNOWN => 3 };
- sub new {
- my $class = shift;
- my %params = @_;
- my $self = {
- cpus => [],
- blacklisted => 0,
- info => undef,
- extendedinfo => undef,
- };
- bless $self, $class;
- $self->init(%params);
- return $self;
- }
- sub init {
- my $self = shift;
- my %params = @_;
- my $type = 0;
- foreach ($self->get_snmp_table_objects(
- 'CISCO-PROCESS-MIB', 'cpmCPUTotalTable')) {
- $_->{cpmCPUTotalIndex} ||= $type++;
- push(@{$self->{cpus}},
- NWC::CiscoIOS::Component::CpuSubsystem::Cpu->new(%{$_}));
- }
- if (scalar(@{$self->{cpus}}) == 0) {
- # maybe too old. i fake a cpu. be careful. this is a really bad hack
- my $response = $self->get_request(
- -varbindlist => [
- $NWC::Device::mibs_and_oids->{'OLD-CISCO-CPU-MIB'}->{avgBusy1},
- $NWC::Device::mibs_and_oids->{'OLD-CISCO-CPU-MIB'}->{avgBusy5},
- $NWC::Device::mibs_and_oids->{'OLD-CISCO-CPU-MIB'}->{busyPer},
- ]
- );
- if (exists $response->{$NWC::Device::mibs_and_oids->{'OLD-CISCO-CPU-MIB'}->{avgBusy1}}) {
- push(@{$self->{cpus}},
- NWC::CiscoIOS::Component::CpuSubsystem::Cpu->new(
- cpmCPUTotalPhysicalIndex => 0, #fake
- cpmCPUTotalIndex => 0, #fake
- cpmCPUTotal5sec => 0, #fake
- cpmCPUTotal5secRev => 0, #fake
- cpmCPUTotal1min => $response->{$NWC::Device::mibs_and_oids->{'OLD-CISCO-CPU-MIB'}->{avgBusy1}},
- cpmCPUTotal1minRev => $response->{$NWC::Device::mibs_and_oids->{'OLD-CISCO-CPU-MIB'}->{avgBusy1}},
- cpmCPUTotal5min => $response->{$NWC::Device::mibs_and_oids->{'OLD-CISCO-CPU-MIB'}->{avgBusy5}},
- cpmCPUTotal5minRev => $response->{$NWC::Device::mibs_and_oids->{'OLD-CISCO-CPU-MIB'}->{avgBusy5}},
- cpmCPUMonInterval => 0, #fake
- cpmCPUTotalMonIntervalValue => 0, #fake
- cpmCPUInterruptMonIntervalValue => 0, #fake
- ));
- }
- }
- }
- sub check {
- my $self = shift;
- my $errorfound = 0;
- $self->add_info('checking cpus');
- $self->blacklist('ff', '');
- if (scalar (@{$self->{cpus}}) == 0) {
- } else {
- foreach (@{$self->{cpus}}) {
- $_->check();
- }
- }
- }
- sub dump {
- my $self = shift;
- foreach (@{$self->{cpus}}) {
- $_->dump();
- }
- }
- package NWC::CiscoIOS::Component::CpuSubsystem::Cpu;
- our @ISA = qw(NWC::CiscoIOS::Component::CpuSubsystem);
- use strict;
- use constant { OK => 0, WARNING => 1, CRITICAL => 2, UNKNOWN => 3 };
- sub new {
- my $class = shift;
- my %params = @_;
- my $self = {
- blacklisted => 0,
- info => undef,
- extendedinfo => undef,
- };
- foreach my $param (qw(cpmCPUTotalIndex cpmCPUTotalPhysicalIndex
- cpmCPUTotal5sec cpmCPUTotal1min cpmCPUTotal5min
- cpmCPUTotal5secRev cpmCPUTotal1minRev cpmCPUTotal5minRev
- cpmCPUMonInterval cpmCPUTotalMonIntervalValue
- cpmCPUInterruptMonIntervalValue)) {
- if (exists $params{$param}) {
- $self->{$param} = $params{$param};
- }
- }
- bless $self, $class;
- if (exists $params{cpmCPUTotal5minRev}) {
- $self->{usage} = $params{cpmCPUTotal5minRev};
- } else {
- $self->{usage} = $params{cpmCPUTotal5min};
- }
- if ($self->{cpmCPUTotalPhysicalIndex}) {
- my $entPhysicalName = '1.3.6.1.2.1.47.1.1.1.1.7';
- $self->{entPhysicalName} = $self->get_request(
- -varbindlist => [$entPhysicalName.'.'.$self->{cpmCPUTotalPhysicalIndex}]
- );
- $self->{entPhysicalName} = $self->{entPhysicalName}->{$entPhysicalName.'.'.$self->{cpmCPUTotalPhysicalIndex}};
- } else {
- $self->{entPhysicalName} = $self->{cpmCPUTotalIndex};
- }
- return $self;
- }
- sub check {
- my $self = shift;
- $self->blacklist('c', $self->{cpmCPUTotalPhysicalIndex});
- my $info = sprintf 'cpu %s usage (5 min avg.) is %.2f%%',
- $self->{entPhysicalName}, $self->{usage};
- $self->add_info($info);
- $self->set_thresholds(warning => 80, critical => 90);
- $self->add_message($self->check_thresholds($self->{usage}), $info);
- $self->add_perfdata(
- label => 'cpu_'.$self->{entPhysicalName}.'_usage',
- value => $self->{usage},
- uom => '%',
- warning => $self->{warning},
- critical => $self->{critical},
- );
- }
- sub dump {
- my $self = shift;
- printf "[CPU_%s]\n", $self->{cpmCPUTotalPhysicalIndex};
- foreach (qw(cpmCPUTotalIndex cpmCPUTotalPhysicalIndex cpmCPUTotal5sec cpmCPUTotal1min cpmCPUTotal5min cpmCPUTotal5secRev cpmCPUTotal1minRev cpmCPUTotal5minRev cpmCPUMonInterval cpmCPUTotalMonIntervalValue cpmCPUInterruptMonIntervalValue)) {
- if (exists $self->{$_}) {
- printf "%s: %s\n", $_, $self->{$_};
- }
- }
- printf "info: %s\n", $self->{info};
- printf "\n";
- }
- package NWC::CiscoIOS::Component::MemSubsystem;
- our @ISA = qw(NWC::CiscoIOS);
- use strict;
- use constant { OK => 0, WARNING => 1, CRITICAL => 2, UNKNOWN => 3 };
- sub new {
- my $class = shift;
- my %params = @_;
- my $self = {
- runtime => $params{runtime},
- rawdata => $params{rawdata},
- mems => [],
- blacklisted => 0,
- info => undef,
- extendedinfo => undef,
- };
- bless $self, $class;
- $self->init(%params);
- return $self;
- }
- sub init {
- my $self = shift;
- my %params = @_;
- my $snmpwalk = $params{rawdata};
- my $ignore_redundancy = $params{ignore_redundancy};
- my $type = 0;
- foreach ($self->get_snmp_table_objects(
- 'CISCO-MEMORY-POOL-MIB', 'ciscoMemoryPoolTable')) {
- $_->{ciscoMemoryPoolType} ||= $type++;
- push(@{$self->{mems}},
- NWC::CiscoIOS::Component::MemSubsystem::Mem->new(%{$_}));
- }
- }
- sub check {
- my $self = shift;
- my $errorfound = 0;
- $self->add_info('checking mems');
- $self->blacklist('ff', '');
- if (scalar (@{$self->{mems}}) == 0) {
- } else {
- foreach (@{$self->{mems}}) {
- $_->check();
- }
- }
- }
- sub dump {
- my $self = shift;
- foreach (@{$self->{mems}}) {
- $_->dump();
- }
- }
- package NWC::CiscoIOS::Component::MemSubsystem::Mem;
- our @ISA = qw(NWC::CiscoIOS::Component::MemSubsystem);
- use strict;
- use constant { OK => 0, WARNING => 1, CRITICAL => 2, UNKNOWN => 3 };
- sub new {
- my $class = shift;
- my %params = @_;
- my $self = {
- blacklisted => 0,
- info => undef,
- extendedinfo => undef,
- };
- foreach my $param (qw(ciscoMemoryPoolTable ciscoMemoryPoolEntry
- ciscoMemoryPoolType ciscoMemoryPoolName ciscoMemoryPoolAlternate
- ciscoMemoryPoolValid ciscoMemoryPoolUsed ciscoMemoryPoolFree
- ciscoMemoryPoolLargestFree)) {
- $self->{$param} = $params{$param};
- }
- bless $self, $class;
- $self->{usage} = 100 * $params{ciscoMemoryPoolUsed} /
- ($params{ciscoMemoryPoolFree} + $params{ciscoMemoryPoolUsed});
- return $self;
- }
- sub check {
- my $self = shift;
- $self->blacklist('m', $self->{ciscoMemoryPoolType});
- my $info = sprintf 'mempool %s usage is %.2f%%',
- $self->{ciscoMemoryPoolName}, $self->{usage};
- $self->add_info($info);
- $self->set_thresholds(warning => 80, critical => 90);
- $self->add_message($self->check_thresholds($self->{usage}), $info);
- $self->add_perfdata(
- label => $self->{ciscoMemoryPoolName}.'_usage',
- value => $self->{usage},
- uom => '%',
- warning => $self->{warning},
- critical => $self->{critical}
- );
- }
- sub dump {
- my $self = shift;
- printf "[MEMPOOL_%s]\n", $self->{ciscoMemoryPoolType};
- foreach (qw(ciscoMemoryPoolType ciscoMemoryPoolName ciscoMemoryPoolAlternate ciscoMemoryPoolValid ciscoMemoryPoolUsed ciscoMemoryPoolFree ciscoMemoryPoolLargestFree)) {
- printf "%s: %s\n", $_, $self->{$_};
- }
- printf "info: %s\n", $self->{info};
- printf "\n";
- }
- package NWC::CiscoIOS::Component::EnvironmentalSubsystem;
- our @ISA = qw(NWC::CiscoIOS);
- use strict;
- use constant { OK => 0, WARNING => 1, CRITICAL => 2, UNKNOWN => 3 };
- sub new {
- my $class = shift;
- my %params = @_;
- my $self = {
- runtime => $params{runtime},
- rawdata => $params{rawdata},
- method => $params{method},
- condition => $params{condition},
- status => $params{status},
- fan_subsystem => undef,
- temperature_subsystem => undef,
- powersupply_subsystem => undef,
- voltage_subsystem => undef,
- blacklisted => 0,
- info => undef,
- extendedinfo => undef,
- };
- bless $self, $class;
- $self->init(%params);
- return $self;
- }
- sub init {
- my $self = shift;
- my %params = @_;
- #
- # 1.3.6.1.4.1.9.9.13.1.1.0 ciscoEnvMonPresent (irgendein typ of envmon)
- #
- $self->{fan_subsystem} =
- NWC::CiscoIOS::Component::FanSubsystem->new(%params);
- $self->{temperature_subsystem} =
- NWC::CiscoIOS::Component::TemperatureSubsystem->new(%params);
- $self->{powersupply_subsystem} =
- NWC::CiscoIOS::Component::SupplySubsystem->new(%params);
- $self->{voltage_subsystem} =
- NWC::CiscoIOS::Component::VoltageSubsystem->new(%params);
- }
- sub check {
- my $self = shift;
- my $errorfound = 0;
- $self->{fan_subsystem}->check();
- $self->{temperature_subsystem}->check();
- $self->{voltage_subsystem}->check();
- $self->{powersupply_subsystem}->check();
- if (! $self->check_messages()) {
- $self->add_message(OK, "environmental hardware working fine");
- }
- }
- sub dump {
- my $self = shift;
- $self->{fan_subsystem}->dump();
- $self->{temperature_subsystem}->dump();
- $self->{voltage_subsystem}->dump();
- $self->{powersupply_subsystem}->dump();
- }
- package NWC::CiscoIOS::Component::TemperatureSubsystem;
- our @ISA = qw(NWC::CiscoIOS::Component::EnvironmentalSubsystem);
- use strict;
- use constant { OK => 0, WARNING => 1, CRITICAL => 2, UNKNOWN => 3 };
- sub new {
- my $class = shift;
- my %params = @_;
- my $self = {
- temperatures => [],
- blacklisted => 0,
- info => undef,
- extendedinfo => undef,
- };
- bless $self, $class;
- $self->init(%params);
- return $self;
- }
- sub init {
- my $self = shift;
- my $tempcnt = 0;
- foreach ($self->get_snmp_table_objects(
- 'CISCO-ENVMON-MIB', 'ciscoEnvMonTemperatureStatusTable')) {
- $_->{ciscoEnvMonTemperatureStatusIndex} = $tempcnt++ if (! exists $_->{ciscoEnvMonTemperatureStatusIndex});
- push(@{$self->{temperatures}},
- NWC::CiscoIOS::Component::TemperatureSubsystem::Temperature->new(%{$_}));
- }
- }
- sub check {
- my $self = shift;
- my $errorfound = 0;
- $self->add_info('checking temperatures');
- $self->blacklist('t', '');
- if (scalar (@{$self->{temperatures}}) == 0) {
- } else {
- foreach (@{$self->{temperatures}}) {
- $_->check();
- }
- }
- }
- sub dump {
- my $self = shift;
- foreach (@{$self->{temperatures}}) {
- $_->dump();
- }
- }
- package NWC::CiscoIOS::Component::TemperatureSubsystem::Temperature;
- our @ISA = qw(NWC::CiscoIOS::Component::TemperatureSubsystem);
- use strict;
- use constant { OK => 0, WARNING => 1, CRITICAL => 2, UNKNOWN => 3 };
- sub new {
- my $class = shift;
- my %params = @_;
- my $self = {
- blacklisted => 0,
- info => undef,
- extendedinfo => undef,
- };
- foreach my $param (qw(ciscoEnvMonTemperatureStatusIndex
- ciscoEnvMonTemperatureStatusDescr ciscoEnvMonTemperatureStatusValue
- ciscoEnvMonTemperatureThreshold ciscoEnvMonTemperatureLastShutdown
- ciscoEnvMonTemperatureState)) {
- $self->{$param} = $params{$param};
- }
- $self->{ciscoEnvMonTemperatureStatusIndex} ||= 0;
- $self->{ciscoEnvMonTemperatureLastShutdown} ||= 0;
- if ($self->{ciscoEnvMonTemperatureStatusValue}) {
- bless $self, $class;
- } else {
- bless $self, $class.'::Simple';
- }
- return $self;
- }
- sub check {
- my $self = shift;
- $self->blacklist('t', $self->{ciscoEnvMonTemperatureStatusIndex});
- if ($self->{ciscoEnvMonTemperatureStatusValue} >
- $self->{ciscoEnvMonTemperatureThreshold}) {
- $self->add_info(sprintf 'temperature %d %s is too high (%d of %d max = %s)',
- $self->{ciscoEnvMonTemperatureStatusIndex},
- $self->{ciscoEnvMonTemperatureStatusDescr},
- $self->{ciscoEnvMonTemperatureStatusValue},
- $self->{ciscoEnvMonTemperatureThreshold},
- $self->{ciscoEnvMonTemperatureState});
- if ($self->{ciscoEnvMonTemperatureState} eq 'warning') {
- $self->add_message(WARNING, $self->{info});
- } elsif ($self->{ciscoEnvMonTemperatureState} eq 'critical') {
- $self->add_message(CRITICAL, $self->{info});
- }
- } else {
- $self->add_info(sprintf 'temperature %d %s is %d (of %d max = normal)',
- $self->{ciscoEnvMonTemperatureStatusIndex},
- $self->{ciscoEnvMonTemperatureStatusDescr},
- $self->{ciscoEnvMonTemperatureStatusValue},
- $self->{ciscoEnvMonTemperatureThreshold},
- $self->{ciscoEnvMonTemperatureState});
- }
- $self->add_perfdata(
- label => sprintf('temp_%s', $self->{ciscoEnvMonTemperatureStatusIndex}),
- value => $self->{ciscoEnvMonTemperatureStatusValue},
- warning => $self->{ciscoEnvMonTemperatureThreshold},
- critical => undef,
- );
- }
- sub dump {
- my $self = shift;
- printf "[TEMP_%s]\n", $self->{ciscoEnvMonTemperatureStatusIndex};
- foreach (qw(ciscoEnvMonTemperatureStatusIndex ciscoEnvMonTemperatureStatusDescr ciscoEnvMonTemperatureStatusValue ciscoEnvMonTemperatureThreshold ciscoEnvMonTemperatureLastShutdown ciscoEnvMonTemperatureState)) {
- printf "%s: %s\n", $_, $self->{$_};
- }
- printf "info: %s\n", $self->{info};
- printf "\n";
- }
- package NWC::CiscoIOS::Component::TemperatureSubsystem::Temperature::Simple;
- our @ISA = qw(NWC::CiscoIOS::Component::TemperatureSubsystem::Temperature);
- use strict;
- use constant { OK => 0, WARNING => 1, CRITICAL => 2, UNKNOWN => 3 };
- sub new {
- my $class = shift;
- my %params = @_;
- my $self = {
- runtime => $params{runtime},
- ciscoEnvMonTemperatureStatusIndex => $params{ciscoEnvMonTemperatureStatusIndex} || 0,
- ciscoEnvMonTemperatureStatusDescr => $params{ciscoEnvMonTemperatureStatusDescr},
- ciscoEnvMonTemperatureState => $params{ciscoEnvMonTemperatureState},
- blacklisted => 0,
- info => undef,
- extendedinfo => undef,
- };
- bless $self, $class;
- return $self;
- }
- sub check {
- my $self = shift;
- $self->blacklist('t', $self->{ciscoEnvMonTemperatureStatusIndex});
- $self->add_info(sprintf 'temperature %d %s is %s',
- $self->{ciscoEnvMonTemperatureStatusIndex},
- $self->{ciscoEnvMonTemperatureStatusDescr},
- $self->{ciscoEnvMonTemperatureState});
- if ($self->{ciscoEnvMonTemperatureState} ne 'normal') {
- if ($self->{ciscoEnvMonTemperatureState} eq 'warning') {
- $self->add_message(WARNING, $self->{info});
- } elsif ($self->{ciscoEnvMonTemperatureState} eq 'critical') {
- $self->add_message(CRITICAL, $self->{info});
- }
- } else {
- }
- }
- sub dump {
- my $self = shift;
- printf "[TEMP_%s]\n", $self->{ciscoEnvMonTemperatureStatusIndex};
- foreach (qw(ciscoEnvMonTemperatureStatusIndex ciscoEnvMonTemperatureStatusDescr ciscoEnvMonTemperatureState)) {
- printf "%s: %s\n", $_, $self->{$_};
- }
- printf "info: %s\n", $self->{info};
- printf "\n";
- }
- package NWC::CiscoIOS::Component::SupplySubsystem;
- our @ISA = qw(NWC::CiscoIOS::Component::EnvironmentalSubsystem);
- use strict;
- use constant { OK => 0, WARNING => 1, CRITICAL => 2, UNKNOWN => 3 };
- sub new {
- my $class = shift;
- my %params = @_;
- my $self = {
- supplies => [],
- blacklisted => 0,
- info => undef,
- extendedinfo => undef,
- };
- bless $self, $class;
- $self->init(%params);
- return $self;
- }
- sub init {
- my $self = shift;
- foreach ($self->get_snmp_table_objects(
- 'CISCO-ENVMON-MIB', 'ciscoEnvMonSupplyStatusTable')) {
- push(@{$self->{supplies}},
- NWC::CiscoIOS::Component::SupplySubsystem::Supply->new(%{$_}));
- }
- }
- sub check {
- my $self = shift;
- my $errorfound = 0;
- $self->add_info('checking supplies');
- $self->blacklist('ps', '');
- if (scalar (@{$self->{supplies}}) == 0) {
- } else {
- foreach (@{$self->{supplies}}) {
- $_->check();
- }
- }
- }
- sub dump {
- my $self = shift;
- foreach (@{$self->{supplies}}) {
- $_->dump();
- }
- }
- package NWC::CiscoIOS::Component::SupplySubsystem::Supply;
- our @ISA = qw(NWC::CiscoIOS::Component::SupplySubsystem);
- use strict;
- use constant { OK => 0, WARNING => 1, CRITICAL => 2, UNKNOWN => 3 };
- sub new {
- my $class = shift;
- my %params = @_;
- my $self = {
- blacklisted => 0,
- info => undef,
- extendedinfo => undef,
- };
- foreach my $param (qw(ciscoEnvMonSupplyStatusIndex
- ciscoEnvMonSupplyStatusDescr ciscoEnvMonSupplyState
- ciscoEnvMonSupplySource)) {
- $self->{$param} = $params{$param};
- }
- $self->{ciscoEnvMonSupplyStatusIndex} ||= 0;
- bless $self, $class;
- return $self;
- }
- sub check {
- my $self = shift;
- $self->blacklist('f', $self->{ciscoEnvMonSupplyStatusIndex});
- $self->add_info(sprintf 'powersupply %d (%s) is %s',
- $self->{ciscoEnvMonSupplyStatusIndex},
- $self->{ciscoEnvMonSupplyStatusDescr},
- $self->{ciscoEnvMonSupplyState});
- if ($self->{ciscoEnvMonSupplyState} eq 'notPresent') {
- } elsif ($self->{ciscoEnvMonSupplyState} ne 'normal') {
- $self->add_message(CRITICAL, $self->{info});
- }
- }
- sub dump {
- my $self = shift;
- printf "[PS_%s]\n", $self->{ciscoEnvMonSupplyStatusIndex};
- foreach (qw(ciscoEnvMonSupplyStatusIndex ciscoEnvMonSupplyStatusDescr ciscoEnvMonSupplyState ciscoEnvMonSupplySource)) {
- printf "%s: %s\n", $_, $self->{$_};
- }
- printf "info: %s\n", $self->{info};
- printf "\n";
- }
- package NWC::CiscoIOS::Component::VoltageSubsystem;
- our @ISA = qw(NWC::CiscoIOS::Component::EnvironmentalSubsystem);
- use strict;
- use constant { OK => 0, WARNING => 1, CRITICAL => 2, UNKNOWN => 3 };
- sub new {
- my $class = shift;
- my %params = @_;
- my $self = {
- voltages => [],
- blacklisted => 0,
- info => undef,
- extendedinfo => undef,
- };
- bless $self, $class;
- $self->init(%params);
- return $self;
- }
- sub init {
- my $self = shift;
- my $index = 0;
- foreach ($self->get_snmp_table_objects(
- 'CISCO-ENVMON-MIB', 'ciscoEnvMonVoltageStatusTable')) {
- $_->{ciscoEnvMonVoltageStatusIndex} ||= $index++;
- push(@{$self->{voltages}},
- NWC::CiscoIOS::Component::VoltageSubsystem::Voltage->new(%{$_}));
- }
- }
- sub check {
- my $self = shift;
- my $errorfound = 0;
- $self->add_info('checking voltages');
- $self->blacklist('ff', '');
- if (scalar (@{$self->{voltages}}) == 0) {
- } else {
- foreach (@{$self->{voltages}}) {
- $_->check();
- }
- }
- }
- sub dump {
- my $self = shift;
- foreach (@{$self->{voltages}}) {
- $_->dump();
- }
- }
- package NWC::CiscoIOS::Component::VoltageSubsystem::Voltage;
- our @ISA = qw(NWC::CiscoIOS::Component::VoltageSubsystem);
- use strict;
- use constant { OK => 0, WARNING => 1, CRITICAL => 2, UNKNOWN => 3 };
- sub new {
- my $class = shift;
- my %params = @_;
- my $self = {
- blacklisted => 0,
- info => undef,
- extendedinfo => undef,
- };
- foreach my $param (qw(ciscoEnvMonVoltageStatusTable
- ciscoEnvMonVoltageStatusEntry ciscoEnvMonVoltageStatusIndex
- ciscoEnvMonVoltageStatusDescr ciscoEnvMonVoltageStatusValue
- ciscoEnvMonVoltageThresholdLow ciscoEnvMonVoltageThresholdHigh
- ciscoEnvMonVoltageLastShutdown ciscoEnvMonVoltageState)) {
- $self->{$param} = $params{$param};
- }
- bless $self, $class;
- return $self;
- }
- sub check {
- my $self = shift;
- $self->blacklist('v', $self->{ciscoEnvMonVoltageStatusIndex});
- $self->add_info(sprintf 'voltage %d (%s) is %s',
- $self->{ciscoEnvMonVoltageStatusIndex},
- $self->{ciscoEnvMonVoltageStatusDescr},
- $self->{ciscoEnvMonVoltageState});
- if ($self->{ciscoEnvMonVoltageState} eq 'notPresent') {
- } elsif ($self->{ciscoEnvMonVoltageState} ne 'normal') {
- $self->add_message(CRITICAL, $self->{info});
- }
- $self->add_perfdata(
- label => sprintf('mvolt_%s', $self->{ciscoEnvMonVoltageStatusIndex}),
- value => $self->{ciscoEnvMonVoltageStatusValue},
- warning => $self->{ciscoEnvMonVoltageThresholdLow},
- critical => $self->{ciscoEnvMonVoltageThresholdHigh},
- );
- }
- sub dump {
- my $self = shift;
- printf "[VOLTAGE_%s]\n", $self->{ciscoEnvMonVoltageStatusIndex};
- foreach (qw(ciscoEnvMonVoltageStatusTable ciscoEnvMonVoltageStatusEntry ciscoEnvMonVoltageStatusIndex ciscoEnvMonVoltageStatusDescr ciscoEnvMonVoltageStatusValue ciscoEnvMonVoltageThresholdLow ciscoEnvMonVoltageThresholdHigh ciscoEnvMonVoltageLastShutdown ciscoEnvMonVoltageState)) {
- printf "%s: %s\n", $_, $self->{$_};
- }
- printf "info: %s\n", $self->{info};
- printf "\n";
- }
- package NWC::CiscoIOS::Component::FanSubsystem;
- our @ISA = qw(NWC::CiscoIOS::Component::EnvironmentalSubsystem);
- use strict;
- use constant { OK => 0, WARNING => 1, CRITICAL => 2, UNKNOWN => 3 };
- sub new {
- my $class = shift;
- my %params = @_;
- my $self = {
- fans => [],
- blacklisted => 0,
- info => undef,
- extendedinfo => undef,
- };
- bless $self, $class;
- $self->init(%params);
- return $self;
- }
- sub init {
- my $self = shift;
- foreach ($self->get_snmp_table_objects(
- 'CISCO-ENVMON-MIB', 'ciscoEnvMonFanStatusTable')) {
- push(@{$self->{fans}},
- NWC::CiscoIOS::Component::FanSubsystem::Fan->new(%{$_}));
- }
- }
- sub check {
- my $self = shift;
- my $errorfound = 0;
- $self->add_info('checking fans');
- $self->blacklist('ff', '');
- if (scalar (@{$self->{fans}}) == 0) {
- } else {
- foreach (@{$self->{fans}}) {
- $_->check();
- }
- }
- }
- sub dump {
- my $self = shift;
- foreach (@{$self->{fans}}) {
- $_->dump();
- }
- }
- package NWC::CiscoIOS::Component::FanSubsystem::Fan;
- our @ISA = qw(NWC::CiscoIOS::Component::FanSubsystem);
- use strict;
- use constant { OK => 0, WARNING => 1, CRITICAL => 2, UNKNOWN => 3 };
- sub new {
- my $class = shift;
- my %params = @_;
- my $self = {
- blacklisted => 0,
- info => undef,
- extendedinfo => undef,
- };
- foreach my $param (qw(ciscoEnvMonFanStatusIndex
- ciscoEnvMonFanStatusDescr ciscoEnvMonFanState)) {
- $self->{$param} = $params{$param};
- }
- $self->{ciscoEnvMonFanStatusIndex} ||= 0;
- bless $self, $class;
- return $self;
- }
- sub check {
- my $self = shift;
- $self->blacklist('f', $self->{ciscoEnvMonFanStatusIndex});
- $self->add_info(sprintf 'fan %d (%s) is %s',
- $self->{ciscoEnvMonFanStatusIndex},
- $self->{ciscoEnvMonFanStatusDescr},
- $self->{ciscoEnvMonFanState});
- if ($self->{ciscoEnvMonFanState} eq 'notPresent') {
- } elsif ($self->{ciscoEnvMonFanState} ne 'normal') {
- $self->add_message(CRITICAL, $self->{info});
- }
- }
- sub dump {
- my $self = shift;
- printf "[FAN_%s]\n", $self->{ciscoEnvMonFanStatusIndex};
- foreach (qw(ciscoEnvMonFanStatusIndex ciscoEnvMonFanStatusDescr
- ciscoEnvMonFanState)) {
- printf "%s: %s\n", $_, $self->{$_};
- }
- printf "info: %s\n", $self->{info};
- printf "\n";
- }
- package NWC::CiscoIOS;
- use strict;
- use constant { OK => 0, WARNING => 1, CRITICAL => 2, UNKNOWN => 3 };
- our @ISA = qw(NWC::Cisco);
- sub init {
- my $self = shift;
- $self->{components} = {
- powersupply_subsystem => undef,
- fan_subsystem => undef,
- temperature_subsystem => undef,
- cpu_subsystem => undef,
- memory_subsystem => undef,
- disk_subsystem => undef,
- environmental_subsystem => undef,
- };
- $self->{serial} = 'unknown';
- $self->{product} = 'unknown';
- $self->{romversion} = 'unknown';
- # serial is 1.3.6.1.2.1.47.1.1.1.1.11.1
- #$self->collect();
- if (! $self->check_messages()) {
- ##$self->set_serial();
- if ($self->mode =~ /device::hardware::health/) {
- $self->analyze_environmental_subsystem();
- #$self->auto_blacklist();
- $self->check_environmental_subsystem();
- } elsif ($self->mode =~ /device::hardware::load/) {
- $self->analyze_cpu_subsystem();
- #$self->auto_blacklist();
- $self->check_cpu_subsystem();
- } elsif ($self->mode =~ /device::hardware::memory/) {
- $self->analyze_mem_subsystem();
- #$self->auto_blacklist();
- $self->check_mem_subsystem();
- } elsif ($self->mode =~ /device::interfaces/) {
- $self->analyze_interface_subsystem();
- $self->check_interface_subsystem();
- } elsif ($self->mode =~ /device::shinken::interface/) {
- $self->analyze_interface_subsystem();
- $self->shinken_interface_subsystem();
- } elsif ($self->mode =~ /device::hsrp/) {
- $self->analyze_hsrp_subsystem();
- $self->check_hsrp_subsystem();
- }
- }
- }
- sub analyze_hsrp_subsystem {
- my $self = shift;
- $self->{components}->{hsrp} =
- NWC::HSRP::Component::HSRPSubsystem->new();
- }
- sub analyze_environmental_subsystem {
- my $self = shift;
- $self->{components}->{environmental_subsystem} =
- NWC::CiscoIOS::Component::EnvironmentalSubsystem->new();
- }
- sub analyze_interface_subsystem {
- my $self = shift;
- $self->{components}->{interface_subsystem} =
- NWC::IFMIB::Component::InterfaceSubsystem->new();
- }
- sub analyze_cpu_subsystem {
- my $self = shift;
- $self->{components}->{cpu_subsystem} =
- NWC::CiscoIOS::Component::CpuSubsystem->new();
- }
- sub analyze_mem_subsystem {
- my $self = shift;
- $self->{components}->{mem_subsystem} =
- NWC::CiscoIOS::Component::MemSubsystem->new();
- }
- sub check_hsrp_subsystem {
- my $self = shift;
- $self->{components}->{hsrp}->check();
- $self->{components}->{hsrp}->dump()
- if $self->opts->verbose >= 2;
- }
- sub check_environmental_subsystem {
- my $self = shift;
- $self->{components}->{environmental_subsystem}->check();
- $self->{components}->{environmental_subsystem}->dump()
- if $self->opts->verbose >= 2;
- }
- sub check_interface_subsystem {
- my $self = shift;
- $self->{components}->{interface_subsystem}->check();
- $self->{components}->{interface_subsystem}->dump()
- if $self->opts->verbose >= 2;
- }
- sub check_cpu_subsystem {
- my $self = shift;
- $self->{components}->{cpu_subsystem}->check();
- $self->{components}->{cpu_subsystem}->dump()
- if $self->opts->verbose >= 2;
- }
- sub check_mem_subsystem {
- my $self = shift;
- $self->{components}->{mem_subsystem}->check();
- $self->{components}->{mem_subsystem}->dump()
- if $self->opts->verbose >= 2;
- }
- sub shinken_interface_subsystem {
- my $self = shift;
- my $attr = sprintf "%s", join(',', map {
- sprintf '%s$(%s)$$()$', $_->{ifDescr}, $_->{ifIndex}
- } @{$self->{components}->{interface_subsystem}->{interfaces}});
- printf <<'EOEO', $self->opts->hostname(), $self->opts->hostname(), $attr;
- define host {
- host_name %s
- address %s
- use default-host
- _interfaces %s
- }
- EOEO
- printf <<'EOEO', $self->opts->hostname();
- define service {
- host_name %s
- service_description net_cpu
- check_command check_nwc_health!cpu-load!80%%!90%%
- }
- EOEO
- printf <<'EOEO', $self->opts->hostname();
- define service {
- host_name %s
- service_description net_mem
- check_command check_nwc_health!memory-usage!80%%!90%%
- }
- EOEO
- printf <<'EOEO', $self->opts->hostname();
- define service {
- host_name %s
- service_description net_ifusage_$KEY$
- check_command check_nwc_health!interface-usage!$VALUE1$!$VALUE2$
- duplicate_foreach _interfaces
- default_value 80%%|90%%
- }
- EOEO
- }
- package NWC::CiscoNXOS::Component::CpuSubsystem;
- our @ISA = qw(NWC::CiscoNXOS);
- use strict;
- use constant { OK => 0, WARNING => 1, CRITICAL => 2, UNKNOWN => 3 };
- sub new {
- my $class = shift;
- my %params = @_;
- my $self = {
- cpus => [],
- blacklisted => 0,
- info => undef,
- extendedinfo => undef,
- };
- bless $self, $class;
- $self->init(%params);
- return $self;
- }
- sub init {
- my $self = shift;
- my %params = @_;
- my $type = 0;
- foreach ($self->get_snmp_table_objects(
- 'CISCO-PROCESS-MIB', 'cpmCPUTotalTable')) {
- $_->{cpmCPUTotalIndex} ||= $type++;
- push(@{$self->{cpus}},
- NWC::CiscoNXOS::Component::CpuSubsystem::Cpu->new(%{$_}));
- }
- if (scalar(@{$self->{cpus}}) == 0) {
- # maybe too old. i fake a cpu. be careful. this is a really bad hack
- my $response = $self->get_request(
- -varbindlist => [
- $NWC::Device::mibs_and_oids->{'OLD-CISCO-CPU-MIB'}->{avgBusy1},
- $NWC::Device::mibs_and_oids->{'OLD-CISCO-CPU-MIB'}->{avgBusy5},
- $NWC::Device::mibs_and_oids->{'OLD-CISCO-CPU-MIB'}->{busyPer},
- ]
- );
- if (exists $response->{$NWC::Device::mibs_and_oids->{'OLD-CISCO-CPU-MIB'}->{avgBusy1}}) {
- push(@{$self->{cpus}},
- NWC::CiscoNXOS::Component::CpuSubsystem::Cpu->new(
- cpmCPUTotalPhysicalIndex => 0, #fake
- cpmCPUTotalIndex => 0, #fake
- cpmCPUTotal5sec => 0, #fake
- cpmCPUTotal5secRev => 0, #fake
- cpmCPUTotal1min => $response->{$NWC::Device::mibs_and_oids->{'OLD-CISCO-CPU-MIB'}->{avgBusy1}},
- cpmCPUTotal1minRev => $response->{$NWC::Device::mibs_and_oids->{'OLD-CISCO-CPU-MIB'}->{avgBusy1}},
- cpmCPUTotal5min => $response->{$NWC::Device::mibs_and_oids->{'OLD-CISCO-CPU-MIB'}->{avgBusy5}},
- cpmCPUTotal5minRev => $response->{$NWC::Device::mibs_and_oids->{'OLD-CISCO-CPU-MIB'}->{avgBusy5}},
- cpmCPUMonInterval => 0, #fake
- cpmCPUTotalMonIntervalValue => 0, #fake
- cpmCPUInterruptMonIntervalValue => 0, #fake
- ));
- }
- }
- }
- sub check {
- my $self = shift;
- my $errorfound = 0;…
Large files files are truncated, but you can click here to view the full file