Projet

Général

Profil

Paste
Télécharger au format
Statistiques
| Branche: | Révision:

root / plugins / disk / megaraid-controller-information @ 5bebfeea

Historique | Voir | Annoter | Télécharger (5,66 ko)

1
#!/usr/bin/perl -w
2
#
3
# Munin plugin for MegaRAID 
4
# This plugin can graph:- Currently Drive Temperature and Error Count
5
# 
6
#---------------------
7
# Examples
8
# Create a symbolic link to MegaRaid_<AdapterNumber>_<temp|media|other|predictive>
9
#       ln -s /usr/share/munin/plugins/MegaRaid_ /etc/munin/plugins/MegaRaid_0_temp
10
#           graph temperature on adapter 0
11
# 
12
#       ln -s /usr/share/munin/plugins/MegaRaid_ /etc/munin/plugins/MegaRaid_0_error
13
#           graph media errors on adapter 0
14
# 
15
#       ln -s /usr/share/munin/plugins/MegaRaid_ /etc/munin/plugins/MegaRaid_1_temp
16
#           graph temperature on adapter 1
17
# 
18
#---------------------
19
# Log
20
# Revision 0.1  2011/04/16  idobson
21
# -First version only basic support of the MegaRaid controller
22
# 
23
# Revision 0.2  2011/04/17 fkatzenb
24
# -Added bash statement to remove the log file created each time MegaCli64 is ran
25
# -Added a few comments and visual changes
26
# 
27
# Revision 1.0 2011/04/17 fkatzenb
28
# -Revamped Code to symbolic link for sensor type and future growth
29
# 
30
# Revision 1.1 2011/04/17 fkatzenb
31
# -Revised scalling
32
# 
33
# Revision 1.2 2011/04/28 fkatzenb
34
# -Added support for graph_info support
35
# -Added warning & critical alerts support
36
# -Added data info
37
# 
38
# Revision 2.0 2011/04/29 fkatzenb
39
# -Added remaining support for SMART Errors
40
# 
41
# Revision 2.1 2011/04/29 fkatzenb
42
# -Added version information for in the graph description
43
# 
44
# 
45
#---------------------
46
# 
47
# Add the following to your /etc/munin/plugin-conf.d/munin-node:
48
# 
49
#       [MegaRaid_*]
50
#       user root
51
# 
52
#---------------------
53
# 
54
# 
55
# Magic markers (optional - used by munin-config and installation scripts):
56
# 
57
#%# family=auto
58
#%# capabilities=autoconf
59
# 
60
my $DisplayVer=2.1;
61

    
62
use strict;
63
use warnings;
64

    
65
my $DevID=0; 		#Device Number found
66
my $DevData=0; 		#Device Data found 
67

    
68
# Parse out Adapter number and parameter desired from file name and remove whitespace
69
my $Parameters=`basename $0 | sed 's/^MegaRaid_//g' | tr '_' '-'` ;	
70
chomp $Parameters;
71
my ($Adapter,$Type)=split(/-/,$Parameters);
72

    
73
# Locate MegaCli64 application and remove whitespace
74
my $Command=`which MegaCli64 megacli | head -n 1`;
75
chomp $Command;
76

    
77
# Use this to define future parameters to monitor
78
my %config = (
79
  temp => {
80
    lookfor => 'Drive Temperature :',
81
    label => 'Temp',
82
    title => "MegaRAID Adapter $Adapter: Drive Temperatures",
83
    vlabel => 'Celsius',
84
    graph_args => '--base 1000 -l 0',
85
    warning => '55',
86
    critical => '65',
87
    info_tag => "Temperature (C)",
88
    description => "Internal Temperatures for drives on Adapter $Adapter."
89
  },
90
  error => {
91
    lookfor => 'Media Error Count: ',
92
    label => 'Media Err',
93
    title => "MegaRAID Adapter $Adapter: Media Errors (SMART)",
94
    vlabel => 'Number of Errors',
95
    graph_args => '--base 1000 -l 0',
96
    warning => '',
97
    critical => '',
98
    info_tag => "Media Errors (SMART)",
99
    description => "Number of SMART errors related to the drive's media on Adapter $Adapter."
100
  },
101
  other => {
102
    lookfor => 'Other Error Count: ',
103
    label => 'Other Err',
104
    title => "MegaRAID Adapter $Adapter: Others Errors (SMART)",
105
    vlabel => 'Number of Errors',
106
    graph_args => '--base 1000 -l 0',
107
    warning => '',
108
    critical => '',
109
    info_tag => "Other Errors (SMART)",
110
    description => "Number of SMART errors not related to the drive's media on Adapter $Adapter."
111
  },
112
  predictive => {
113
    lookfor => 'Predictive Failure Count: ',
114
    label => 'Predictive Err',
115
    title => "MegaRAID Adapter $Adapter: Predictive Errors (SMART)",
116
    vlabel => 'Number of Errors',
117
    graph_args => '--base 1000 -l 0',
118
    warning => '',
119
    critical => '',
120
    info_tag => "Predictive Errors (SMART)",
121
    description => "Number of SMART errors for each drive on Adapter $Adapter."
122
  }
123
);
124

    
125
#Auto config options
126
if ($ARGV[0] and $ARGV[0] eq "autoconf" ) {
127
   if (-e $Command ) {
128
      print "yes\n";
129
      exit 0;
130
      } else {
131
      print "no\n";     
132
      exit 1
133
     }
134
}
135

    
136
#Read Output of MegaRaid command
137
$Command.=" -PDList -a".$Adapter; 
138
my @Output=qx($Command);
139

    
140
#Munin Config Options
141
if ($ARGV[0] and $ARGV[0] eq "config"){
142
   print "graph_title $config{$Type}->{title}\n";
143
   print "graph_vlabel $config{$Type}->{vlabel}\n";
144
   print "graph_args $config{$Type}->{graph_args}\n";
145
   print "graph_scale yes\n";
146
   print "graph_category disk\n";
147
   print "graph_info $config{$Type}->{description} <br />Generated by MegaRaid_, Version $DisplayVer<br />\n";
148
    
149
   foreach my $Line (@Output) {
150
      $Line=~ s/\r//g;
151
      $Line=~ s/\n//g;
152
      
153
      #Find the device ID
154
      if ( $Line=~ m/Slot Number: /i ) { 
155
         $DevID=$Line; 
156
         $DevID=~ s/Slot Number: //;
157
         print "A".$Adapter."_D".$DevID."_$Type.label A$Adapter:D$DevID $config{$Type}->{label}\n";
158
         print "A".$Adapter."_D".$DevID."_$Type.info Adapter: $Adapter / Drive: $DevID - $config{$Type}->{info_tag}\n";
159
         if ($config{$Type}->{warning} ne '' ) {
160
            print "A".$Adapter."_D".$DevID."_$Type.warning $config{$Type}->{warning}\n";
161
            }
162
         if ($config{$Type}->{critical} ne '') {
163
            print "A".$Adapter."_D".$DevID."_$Type.critical $config{$Type}->{critical}\n";
164
            }   
165
      }
166
   } 
167
   exit 0;
168
}
169

    
170
#Actually dump the data
171
foreach my $Line (@Output) {
172
   $Line=~ s/\r//g;
173
   $Line=~ s/\n//g;
174

    
175
   #Find the device ID
176
   if ( $Line=~ m/Slot Number: /i ) { $DevID=$Line; $DevID=~ s/Slot Number: //; chomp $DevID; }
177

    
178
   #Find the data and print it out
179
   if ( $Line=~ m/$config{$Type}->{lookfor}/i ) { 
180
      $DevData=$Line;
181
      $DevData=~s/$config{$Type}->{lookfor}//;
182
      $DevData=~s/C.*//;
183
      chomp $DevData;
184
      print "A".$Adapter."_D".$DevID."_$Type.value $DevData\n";
185
   }
186
}
187

    
188
#Remove log file created by running MegaCli
189
   unlink "MegaSAS.log";
190

    
191
exit 0;