git.lirion.de

Of git, get, and gud

summaryrefslogtreecommitdiffstats
path: root/nagios-plugins-contrib-24.20190301~bpo9+1/check_hpasm/check_hpasm-4.8/plugins-scripts/HP/SNMP/Utils.pm
blob: f2d31a9d8029adef04458c33ea2c66d480836100 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
package SNMP::Utils;

use strict;

{
  sub get_indices {
    my $oids = shift;
    my $entry = shift;
    my $numindices = shift;
    # find all oids beginning with $entry
    # then skip one field for the sequence
    # then read the next numindices fields
    my $entrypat = $entry;
    $entrypat =~ s/\./\\\./g;
    my  _æ_ indices = map {
        /^$entrypat\.\d+\.(.*)/ && $1;
    } grep {
        /^$entrypat/
    } keys %{$oids};
    my %seen = ();
    my  _æ_ o = map {[split /\./]} sort grep !$seen{$_}++,  _æ_ indices;
    return  _æ_ o;
  }

  sub get_size {
    my $oids = shift;
    my $entry = shift;
    my $entrypat = $entry;
    $entrypat =~ s/\./\\\./g;
    my  _æ_ entries = grep {
        /^$entrypat/
    } keys %{$oids};
    return scalar( _æ_ entries);
  }

  sub get_object {
    my $oids = shift;
    my $object = shift;
    my  _æ_ indices =  _æ_ _;
    #my $oid = $object.'.'.join('.',  _æ_ indices);
    my $oid = $object;
    $oid .= '.'.join('.',  _æ_ indices) if ( _æ_ indices);
    return $oids->{$oid};
  }

  sub get_object_value {
    my $oids = shift;
    my $object = shift;
    my $values = shift;
    my  _æ_ indices =  _æ_ _;
    my $key = get_object($oids, $object,  _æ_ indices);
    if (defined $key) {
      return $values->{$key};
    } else {
      return undef;
    }
  }

  #SNMP::Utils::counter([$idxs1, $idxs2], $idx1, $idx2),
  # this flattens a n-dimensional array and returns the absolute position
  # of the element at position idx1,idx2,...,idxn
  # 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
  sub get_number {
    my $indexlists = shift; #, zeiger auf array aus [1, 2]
    my  _æ_ element =  _æ_ _;
    my $dimensions = scalar( _æ_ {$indexlists->[0]});
    my  _æ_ sorted = ();
    my $number = 0;
    if ($dimensions == 1) {
       _æ_ sorted =
          sort { $a->[0] <=> $b->[0] }  _æ_ {$indexlists};
    } elsif ($dimensions == 2) {
       _æ_ sorted =
          sort { $a->[0] <=> $b->[0] || $a->[1] <=> $b->[1] }  _æ_ {$indexlists};
    } elsif ($dimensions == 3) {
       _æ_ sorted =
          sort { $a->[0] <=> $b->[0] || 
                 $a->[1] <=> $b->[1] ||
                 $a->[2] <=> $b->[2] }  _æ_ {$indexlists};
    }
    foreach ( _æ_ sorted) {
      if ($dimensions == 1) {
        if ($_->[0] == $element[0]) {
          last;
        }
      } elsif ($dimensions == 2) {
        if ($_->[0] == $element[0] && $_->[1] == $element[1]) {
          last;
        }
      } elsif ($dimensions == 3) {
        if ($_->[0] == $element[0] && 
            $_->[1] == $element[1] &&
            $_->[2] == $element[2]) {
          last;
        }
      }
      $number++;
    }
    return ++$number;
  }

}