Advertisement
Guest User

Untitled

a guest
Mar 21st, 2019
110
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 7.28 KB | None | 0 0
  1. #!/usr/bin/perl -w
  2. # -*- cperl -*-
  3. =head1 NAME
  4.  
  5. freeipmi - Multigraph-plugin to monitor sensors using FreeIPMI
  6.  
  7. =head1 CONFIGURATION
  8. When used to monitor the local host, plugin config should define user root for direct ipmi access:
  9. [freeipmi]
  10. user root
  11.  
  12. =head2 ENVIRONMENT VARIABLES
  13.  
  14. When used to monitor a foreign host, this plugins use the variables
  15. IPMI_USERNAME and IPMI_PASSWORD to log in on the remote system.
  16.  
  17. =head2 WILDCARD PLUGIN
  18.  
  19. When used for the local host, the plugin should be linked as
  20. non-wildcard plugin, i.e., 'freeipmi', whereas when used to monitor a
  21. foreign host it should be, e.g., 'freeipmi_192.168.0.253'.
  22.  
  23. =head1 DEPENDENCIES
  24.  
  25. The plugin requires FreeIPMI 1.1.5 or later to fetch the information.
  26. Limits set on thresholds are available when using FreeIPMI 1.2.0 or
  27. later.
  28.  
  29. =head1 AUTHOR
  30.  
  31. Diego Elio Pettenò <flameeyes@flameeyes.eu>.
  32. Yutaro Shimamura (yu@github)
  33.  
  34. With help and suggestions of:
  35.  
  36. Bart ten Brinke <info@retrosync.com>
  37.  
  38. =head1 LICENSE
  39.  
  40. GPLv2
  41.  
  42. =head1 MAGIC MARKERS
  43.  
  44. #%# family=auto
  45. #%# capabilities=autoconf
  46.  
  47. =head1 LICENSE
  48.  
  49. GPLv2
  50.  
  51. =head1 MAGIC MARKERS
  52.  
  53. #%# family=auto
  54. #%# capabilities=autoconf
  55.  
  56. =cut
  57.  
  58. use strict;
  59. use Munin::Plugin;
  60.  
  61. $ENV{'LANG'} = "C"; # Force parsable output from sensors.
  62. $ENV{'LC_ALL'} = "C"; # Force parsable output from sensors.
  63. my $IPMISENSORS = $ENV{'ipmisensors'} || 'ipmi-sensors';
  64. my $IPMISEL = $ENV{'ipmisel'} || 'ipmi-sel';
  65.  
  66. $0 =~ /freeipmi(?:_(.+))$/;
  67. my $hostname = $1;
  68.  
  69. my $help_output = `$IPMISENSORS --help`;
  70.  
  71. $IPMISENSORS .= " --output-sensor-thresholds" if $help_output =~ /--output-sensor-thresholds/;
  72. $IPMISENSORS .= " --quiet-cache --comma-separated-output --no-header-output --ignore-not-available-sensors --sensor-types=Temperature,Fan,Current,Voltage";
  73. $IPMISENSORS .= " --hostname=$hostname" if defined($hostname);
  74. $IPMISENSORS .= " --username=$ENV{IPMI_USERNAME}" if defined($ENV{IPMI_USERNAME});
  75. $IPMISENSORS .= " --password=$ENV{IPMI_PASSWORD}" if defined($ENV{IPMI_PASSWORD});
  76.  
  77. $IPMISEL .= " --quiet-cache --comma-separated-output --no-header-output";
  78. $IPMISEL .= " --output-event-state";
  79. $IPMISEL .= " --hostname=$hostname" if defined($hostname);
  80. $IPMISEL .= " --username=$ENV{IPMI_USERNAME}" if defined($ENV{IPMI_USERNAME});
  81. $IPMISEL .= " --password=$ENV{IPMI_PASSWORD}" if defined($ENV{IPMI_PASSWORD});
  82.  
  83. my $output=`$IPMISENSORS 2>/dev/null`;
  84. my $retval=$?;
  85.  
  86. my $sout=`$IPMISEL 2>/dev/null`;
  87. my $sret=$?;
  88.  
  89. if ( defined $ARGV[0] and $ARGV[0] eq 'autoconf' ) {
  90. if ($retval >= 1 || $sret >= 1) {
  91. print "no (ipmi-sensors/sel died)\n";
  92. } elsif ($retval == -1 || $sret == -1) {
  93. print "no (ipmi-sensors/sel not found)\n";
  94. } elsif ($output eq "\n" || $sout eq "\n") {
  95. print "no (no compatible sensors)\n";
  96. } else {
  97. print "yes\n";
  98. }
  99. exit 0;
  100. }
  101.  
  102. my %sensors = (
  103. temp => {
  104. inputs => [],
  105. title => "Temperatures by IPMI",
  106. vlabel => "Degrees Celsius",
  107. graph_args => "--base 1000 -l 0",
  108. },
  109. fan => {
  110. inputs => [],
  111. title => "Fans speed by IPMI",
  112. vlabel => "RPM",
  113. graph_args => "--base 1000 -l 0",
  114. },
  115. power => {
  116. inputs => [],
  117. title => "Power by IPMI",
  118. vlabel => "W",
  119. graph_args => "--base 1000 -l 0",
  120. },
  121. current => {
  122. inputs => [],
  123. title => "Current by IPMI",
  124. vlabel => "A",
  125. graph_args => "--base 1000 -l 0",
  126. },
  127. voltage => {
  128. inputs => [],
  129. title => "Voltages by IPMI",
  130. vlabel => "Volt",
  131. graph_args => "--base 1000 --logarithmic",
  132. },
  133. selcounts => {
  134. inputs => [],
  135. title => "Sel counts by IPMI",
  136. vlabel => "Counts",
  137. graph_args => "--base 1000 -l 0",
  138. },
  139. seltypes => {
  140. inputs => [],
  141. title => "Sel types by IPMI",
  142. vlabel => "Counts",
  143. graph_args => "--base 1000 -l 0",
  144. },
  145. );
  146.  
  147. # ipmi-sensors
  148. my @data = split(/\n/, $output);
  149. foreach my $line (@data) {
  150. my @dataline = split(/,/, $line);
  151.  
  152. my %sensor = (
  153. graphid => "ipmi" . $dataline[0],
  154. value => $dataline[3],
  155. label => $dataline[1]
  156. );
  157. $sensor{lwarn} = (defined($dataline[7]) and $dataline[7] ne "N/A") ? $dataline[7] : '';
  158. $sensor{hwarn} = (defined($dataline[8]) and $dataline[8] ne "N/A") ? $dataline[8] : '';
  159.  
  160. $sensor{lcrit} = (defined($dataline[6]) and $dataline[6] ne "N/A") ? $dataline[6] : '';
  161. $sensor{hcrit} = (defined($dataline[9]) and $dataline[9] ne "N/A") ? $dataline[9] : '';
  162.  
  163. my $type;
  164. if ( $dataline[2] eq "Temperature" ) {
  165. $type = "temp";
  166. } elsif ( $dataline[2] eq "Fan" ) {
  167. $type = "fan"
  168. } elsif ( $dataline[2] eq "Current" and $dataline[4] eq "W" ) {
  169. $type = "power";
  170. } elsif ( $dataline[2] eq "Current" and $dataline[4] eq "A" ) {
  171. $type = "current";
  172. } elsif ( $dataline[2] eq "Voltage" ) {
  173. $type = "voltage";
  174. }
  175.  
  176. push(@{$sensors{$type}->{inputs}}, \%sensor);
  177. }
  178.  
  179.  
  180. if ( defined $ARGV[0] and $ARGV[0] eq 'config' ) {
  181. foreach my $type (keys %sensors) {
  182. # don't print anything if no value is found
  183. next if scalar(@{$sensors{$type}->{inputs}}) == 0;
  184.  
  185. print "host_name $hostname" if defined($hostname);
  186.  
  187. print <<END;
  188.  
  189. multigraph freeipmi_$type
  190. graph_title $sensors{$type}->{title}
  191. graph_vlabel $sensors{$type}->{vlabel}
  192. graph_args $sensors{$type}->{graph_args}
  193. graph_category sensors
  194. END
  195.  
  196. foreach my $sensor (@{$sensors{$type}->{inputs}}) {
  197. print "$sensor->{graphid}.label $sensor->{label}\n";
  198.  
  199. print "$sensor->{graphid}.warning $sensor->{lwarn}:$sensor->{hwarn}\n"
  200. unless $sensor->{lwarn} eq '' and $sensor->{hwarn} eq '';
  201. print "$sensor->{graphid}.critical $sensor->{lcrit}:$sensor->{hcrit}\n"
  202. unless $sensor->{lcrit} eq '' and $sensor->{hcrit} eq '';
  203. }
  204. }
  205.  
  206. print <<END;
  207.  
  208. multigraph freeipmi_selcounts
  209. graph_title $sensors{'selcounts'}->{title}
  210. graph_args $sensors{'selcounts'}->{graph_args}
  211. graph_vlabel $sensors{'selcounts'}->{vlabel}
  212. graph_scale no
  213. graph_category system
  214. graph_printf %3.0lf
  215. ipmiselcNominal.label Nominal
  216. ipmiselcNominal.draw AREASTACK
  217. ipmiselcWarning.label Warning
  218. ipmiselcWarning.draw AREASTACK
  219. ipmiselcWarning.warning 0:0
  220. ipmiselcCritical.label Critical
  221. ipmiselcCritical.draw AREASTACK
  222. ipmiselcCritical.critical 0:0
  223.  
  224. multigraph freeipmi_seltypes
  225. graph_title $sensors{'seltypes'}->{title}
  226. graph_args $sensors{'seltypes'}->{graph_args}
  227. graph_vlabel $sensors{'seltypes'}->{vlabel}
  228. graph_scale no
  229. graph_category system
  230. graph_printf %3.0lf
  231. END
  232. my $sellist =`$IPMISEL -L 2>/dev/null`;
  233. my @sdat = split(/\n/, $sellist);
  234. foreach my $nm (@sdat) {
  235. print "ipmiselt$nm.label $nm\n";
  236. print "ipmiselt$nm.draw AREASTACK\n";
  237. }
  238.  
  239. unless ( ($ENV{MUNIN_CAP_DIRTYCONFIG} || 0) == 1 ) {
  240. exit 0;
  241. }
  242. }
  243.  
  244. # ipmi-sel (shold run after config)
  245. my %selcounts = (
  246. Nominal => {graphid=>"ipmiselcNominal", value=>0},
  247. Warning => {graphid=>"ipmiselcWarning", value=>0},
  248. Critical => {graphid=>"ipmiselcCritical", value=>0}
  249. );
  250. my %seltypes = ();
  251.  
  252. @data = split(/\n/, $sout);
  253. foreach my $line (@data) {
  254. my @dataline = split(/,/, $line);
  255. $dataline[4] =~ s/( |\/)/_/g;
  256. $selcounts{$dataline[5]}->{value}++;
  257. $seltypes{$dataline[4]} //= {graphid=>"ipmiselt$dataline[4]", value=>0};
  258. $seltypes{$dataline[4]}->{value}++;
  259. }
  260. @{$sensors{'selcounts'}->{inputs}} = values %selcounts;
  261. @{$sensors{'seltypes'}->{inputs}} = values %seltypes;
  262.  
  263. foreach my $type (keys %sensors) {
  264. # don't print anything if no value is found
  265. next if scalar(@{$sensors{$type}->{inputs}}) == 0;
  266.  
  267. print "multigraph freeipmi_$type\n";
  268.  
  269. foreach my $sensor (@{$sensors{$type}->{inputs}}) {
  270. print "$sensor->{graphid}.value $sensor->{value}\n";
  271. }
  272. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement