~ubuntu-branches/ubuntu/trusty/nagios-plugins-contrib/trusty-proposed

« back to all changes in this revision

Viewing changes to check_hpasm/check_hpasm-4.6.3.2/plugins-scripts/HP/SNMP/Utils.pm

  • Committer: Package Import Robot
  • Author(s): Bernd Zeimetz, Bernd Zeimetz, Jan Wagner, Evgeni Golov
  • Date: 2013-06-14 20:53:49 UTC
  • Revision ID: package-import@ubuntu.com-20130614205349-34xiy38pm1hzpjoi
Tags: 7.20130614
[ Bernd Zeimetz ]
* [036816ff] Merge pull request #15 from evgeni/master
  check_packages should find security updates on the official security mirror too
* [658a2e93] Add check_checksums nagios plugin.
* [9d5d2056] Updating check_raid.
* [e3ec1293] Updating check_ssl_cert to 1.14.6
* [779543ef] Updating check_hpasm to 4.6.3.2
* [0c838ee9] Updating check_multipath to 0.1.9
* [bec11251] Updating check_whois to 1.13
* [8e0a65d0] Refreshing patches.
* [c0b88cdb] Auto update of debian/copyright
* [59648a17] Fix src link for check_hpasm
* [8c242d0f] Support pre-Wheezy versions of coretutils in check_checksums.
* [7d3d2a06] Update release date in changelog (gah!).
* [768e463b] Merge pull request #16 from evgeni/master
  check_libs: ignore /var/lib/postgresql/ and /var/log/
* [2b9aace5] Bumping standards-Verison, no changes needed.

[ Jan Wagner ]
* [3bb873e4] disable epn for check_rbl

[ Evgeni Golov ]
* [2a7ab4b8] check_libs: ignore /var/spool/

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
package SNMP::Utils;
 
2
 
 
3
use strict;
 
4
 
 
5
{
 
6
  sub get_indices {
 
7
    my $oids = shift;
 
8
    my $entry = shift;
 
9
    my $numindices = shift;
 
10
    # find all oids beginning with $entry
 
11
    # then skip one field for the sequence
 
12
    # then read the next numindices fields
 
13
    my $entrypat = $entry;
 
14
    $entrypat =~ s/\./\\\./g;
 
15
    my @indices = map {
 
16
        /^$entrypat\.\d+\.(.*)/ && $1;
 
17
    } grep {
 
18
        /^$entrypat/
 
19
    } keys %{$oids};
 
20
    my %seen = ();
 
21
    my @o = map {[split /\./]} sort grep !$seen{$_}++, @indices;
 
22
    return @o;
 
23
  }
 
24
 
 
25
  sub get_size {
 
26
    my $oids = shift;
 
27
    my $entry = shift;
 
28
    my $entrypat = $entry;
 
29
    $entrypat =~ s/\./\\\./g;
 
30
    my @entries = grep {
 
31
        /^$entrypat/
 
32
    } keys %{$oids};
 
33
    return scalar(@entries);
 
34
  }
 
35
 
 
36
  sub get_object {
 
37
    my $oids = shift;
 
38
    my $object = shift;
 
39
    my @indices = @_;
 
40
    #my $oid = $object.'.'.join('.', @indices);
 
41
    my $oid = $object;
 
42
    $oid .= '.'.join('.', @indices) if (@indices);
 
43
    return $oids->{$oid};
 
44
  }
 
45
 
 
46
  sub get_object_value {
 
47
    my $oids = shift;
 
48
    my $object = shift;
 
49
    my $values = shift;
 
50
    my @indices = @_;
 
51
    my $key = get_object($oids, $object, @indices);
 
52
    if (defined $key) {
 
53
      return $values->{$key};
 
54
    } else {
 
55
      return undef;
 
56
    }
 
57
  }
 
58
 
 
59
  #SNMP::Utils::counter([$idxs1, $idxs2], $idx1, $idx2),
 
60
  # this flattens a n-dimensional array and returns the absolute position
 
61
  # of the element at position idx1,idx2,...,idxn
 
62
  # element 1,2 in table 0,0 0,1 0,2 1,0 1,1 1,2 2,0 2,1 2,2 is at pos 6
 
63
  sub get_number {
 
64
    my $indexlists = shift; #, zeiger auf array aus [1, 2]
 
65
    my @element = @_;
 
66
    my $dimensions = scalar(@{$indexlists->[0]});
 
67
    my @sorted = ();
 
68
    my $number = 0;
 
69
    if ($dimensions == 1) {
 
70
      @sorted =
 
71
          sort { $a->[0] <=> $b->[0] } @{$indexlists};
 
72
    } elsif ($dimensions == 2) {
 
73
      @sorted =
 
74
          sort { $a->[0] <=> $b->[0] || $a->[1] <=> $b->[1] } @{$indexlists};
 
75
    } elsif ($dimensions == 3) {
 
76
      @sorted =
 
77
          sort { $a->[0] <=> $b->[0] || 
 
78
                 $a->[1] <=> $b->[1] ||
 
79
                 $a->[2] <=> $b->[2] } @{$indexlists};
 
80
    }
 
81
    foreach (@sorted) {
 
82
      if ($dimensions == 1) {
 
83
        if ($_->[0] == $element[0]) {
 
84
          last;
 
85
        }
 
86
      } elsif ($dimensions == 2) {
 
87
        if ($_->[0] == $element[0] && $_->[1] == $element[1]) {
 
88
          last;
 
89
        }
 
90
      } elsif ($dimensions == 3) {
 
91
        if ($_->[0] == $element[0] && 
 
92
            $_->[1] == $element[1] &&
 
93
            $_->[2] == $element[2]) {
 
94
          last;
 
95
        }
 
96
      }
 
97
      $number++;
 
98
    }
 
99
    return ++$number;
 
100
  }
 
101
 
 
102
}
 
103