Thread Perl Skript anpassen (Plugin für Nagios) (22 answers)
Opened by pc-dok at 2014-09-25 14:16

GwenDragon
 2014-09-30 09:21
#177588 #177588
User since
2005-01-17
14758 Artikel
Admin1
[Homepage]
user image
Ungetestete Schnippsel:

Code (perl): (dl )
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
### DOKU ###
=pod

LOGICAL UNIT NUMBER 7
Name:  POOL_0_VMVOL_07
Current State:  Ready

Und hier stehe ich an, ich muss den Code so anpassen, das der mir für Nagios den Output wie folgt generiert:

Name: POOL_0_VMVOL_07, State: Ready

Wenn State nicht Ready ist, dann warning!

=cut

### /DOKU ###

sub check_lun_info {
        open( NAVICLIOUT, "$NAVICLI_CMD -h $opt_host lun -list -state |" );

        my $sp_line = 0;
        my $error_count = 0;
        my %out = ();
        my $warn = 0;
        while (<NAVICLIOUT>) {
        # First lets check for errors before proceeding
        check_for_errors($_);
                
                if (/(LOGICAL UNIT NUMBER)\s+(\d+)/) {
                        #$out{lun}="$1 $2";
                        $out{lun}="$2";
                        next;
                }
                
                if (/(Name:)\s+(\w+)/) {
                        #$out{name} = "$1 $2";
                        $out{name} = "$2";
                        next;
                }
                
                if (/(Current State:)\s+(\w+)/) {
                        #$out{state} = "$1 $2";
                        $out{state} = "$2";
                        $warn = uc $out{state} ne 'READY';
                        ++$error_count if $warn;
                        next;
                }
                
                if (defined $out{state} 
                        and defined $out{lun} 
                        and defined $out{name}) 
                {
                        $output .= "$out{name}:$out{state},";
            %out = ();
                        next;
                }
        }               
        
        close (NAVICLIOUT);
        
        if ($error_count == 0 && $output ne "") {
                $state = 'OK';
        } 
        elsif ($output eq "") {
                $output = "UNKNOWN: No output from $NAVICLI";
                $state = 'UNKNOWN';
        } 
        else {
                 if ($warn) {
                        $state = 'WARNING';
                 }
                 else {          
                        $state = 'CRITICAL';
                 }
        }
    $output =~ s/,$//;
        print $output."\n";
        exit $states{$state};
}


Editiert von GwenDragon: } hinzu; falscher Hashkey
Ausgabe einzeilig formatiert;
mehrere Ausgaben

Last edited: 2014-09-30 14:01:05 +0200 (CEST)

View full thread Perl Skript anpassen (Plugin für Nagios)