Advertisement
opexxx

SNMP Temperature Monitoring HP C3000 Blades

Apr 7th, 2014
257
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Perl 3.81 KB | None | 0 0
  1. #!/usr/bin/perl -w
  2. use MIME::Lite;
  3.  
  4. ###########################################
  5. #This is a ILO in CS3000-1
  6. ###########################################
  7. open(FD, "/usr/local/bin/snmpwalk -v 1 -c communitynamehere 127.0.0.1 .1.3.6.1.4.1.232.6.2.6.8.1.4.0.1 |") || die "Failed: $!\n";
  8. while (<FD>)
  9. {
  10. chomp;
  11. $value = substr $_, 55, 2;
  12. $far = $value * 9 / 5 + 32;
  13. }
  14.  
  15. ##########################################
  16. #This is the FAX Server ILO in CS3000-2
  17. ##########################################
  18. open(FF, "/usr/local/bin/snmpwalk -v 1 -c communitynamehere 127.0.0.1 .1.3.6.1.4.1.232.6.2.6.8.1.4.0.1 |") || die "Failed: $!\n";
  19. while (<FF>)
  20. {
  21. chomp;
  22. $dvalue = substr $_, 55, 2;
  23. $dfar = $dvalue * 9 / 5 + 32;
  24. }
  25. ##########################################
  26. #This is a CPRT03 in C3000-2 in the Server RooM
  27. ##########################################
  28. open(FS, "/usr/local/bin/snmpwalk -v 1 -c communitynamehere 127.0.0.1 .1.3.6.1.4.1.232.6.2.6.8.1.4.0.1 |") || die "Failed: $!\n";
  29. while (<FS>)
  30. {
  31. chomp;
  32. $svalue = substr $_, 55, 2;
  33. $sfar = $svalue * 9 / 5 + 32;
  34. }
  35.  
  36. printf "Current Blade Inlet Ambient Air Temperatures\n\n";
  37. printf "Datacenter\n";
  38. printf "CS3000-1:$far\n";
  39. printf "CS3000-2:$dfar\n";
  40. printf "\n";
  41. printf "ServerRoom\n";
  42. printf "C3000-1:$sfar\n";
  43.  
  44. if ($far > 74){
  45. &alertmail;
  46. }
  47. if ($dfar > 74){
  48. &alertmail;
  49. }
  50. if ($sfar > 82) {
  51. &alertmail;
  52. }
  53. if ($far > 80){
  54. &dcalert;
  55. }
  56. if ($dfar > 80){
  57. &dcalert;
  58. }
  59. if ($sfar > 85) {
  60. &fshalert;
  61. }
  62.  
  63. sub alertmail {
  64. my $from = 'TempMon@foo.com';
  65. my $site = 'foo.com';
  66. my $smtp_host = '10.0.0.1';
  67. my $to = 'alert@foo.com';
  68.  
  69. my $subject = 'Temperature Alert';
  70. my $message_body = "Datacenter Blade Inlet Ambient Temps \n\nCS3000-1: $far\nCS3000-2: $dfar\n\n\nServer Room Blade Inlet Ambient Temp \n\nC3000-1: $sfar\n";
  71.  
  72. ### Create the multipart container
  73. $msg = MIME::Lite->gt;new (
  74.   From => $from,
  75.   To =>gt; $to,
  76.   Subject => $subject,
  77.   Type =>'multipart/mixed'
  78. ) or die "Error creating multipart container: $!\n";
  79.  
  80. ### Add the text message part
  81. $msg->attach (
  82.   Type => 'TEXT',
  83.   Data => $message_body
  84. ) or die "Error adding the text message part: $!\n";
  85.  
  86. ### Send the Message
  87. MIME::Lite->send('smtp', $smtp_host, Timeout=>60);
  88. $msg->send;
  89. }
  90.  
  91. sub dcalert {
  92. my $from = 'alert@foo.com';
  93. my $site = 'foo.com';
  94. my $smtp_host = '10.0.0.1';
  95. my $to = 'alert@foo.com';
  96.  
  97. my $subject = '!!!! DATA CENTER HIGH TEMPERATURE ALERT !!!!';
  98. my $message_body = "Datacenter Blade Inlet Ambient Temps \n\nCS3000-1: $far\nCS3000-2: $dfar\n\n\nServer Room Blade Inlet Ambient Temp \n\nC3000-1: $sfar\n";
  99.  
  100. ### Create the multipart container
  101. $msg = MIME::Lite->new (
  102.   From => $from,
  103.   To => $to,
  104.   Subject => $subject,
  105.   Type =>'multipart/mixed'
  106. ) or die "Error creating multipart container: $!\n";
  107.  
  108. ### Add the text message part
  109. $msg->attach (
  110.   Type => 'TEXT',
  111.   Data => $message_body
  112. ) or die "Error adding the text message part: $!\n";
  113.  
  114. ### Send the Message
  115. MIME::Lite->send('smtp', $smtp_host, Timeout=>60);
  116. $msg->send;
  117. }
  118.  
  119. sub fshalert  {
  120. my $from = 'TempMon@foo.com';
  121. my $site = 'foo.com';
  122. my $smtp_host = '10.0.2.58';
  123. my $to = 'ITS@foo.com';
  124.  
  125. my $subject = '!!!! FSH HIGH TEMPERATURE ALERT !!!!';
  126. my $message_body = "Datacenter Blade Inlet Ambient Temps \n\nFSCH-CS3000-1: $far\nFSCH-CS3000-2: $dfar\n\n\nServer Room Blade Inlet Ambient Temp \n\nFSH-C3000-1: $sfar\n";
  127.  
  128.  
  129. ### Create the multipart container
  130. $msg = MIME::Lite->new (
  131.   From => $from,
  132.   To => $to,
  133.   Subject => $subject,
  134.   Type =>'multipart/mixed'
  135. ) or die "Error creating multipart container: $!\n";
  136.  
  137. ### Add the text message part
  138. $msg->attach (
  139.   Type => 'TEXT',
  140.   Data => $message_body
  141. ) or die "Error adding the text message part: $!\n";
  142.  
  143.  
  144. ### Send the Message
  145. MIME::Lite->send('smtp', $smtp_host, Timeout=>60);
  146. $msg->send;
  147. }
  148.  
  149.  
  150.  
  151.  
  152.  
  153.  
  154.  
  155. close(FS);
  156. close(FF);
  157. close(FD);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement