Advertisement
Guest User

Untitled

a guest
May 4th, 2016
79
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.39 KB | None | 0 0
  1. [1461932408] SERVICE NOTIFICATION: nagiosadmin;appserver;Swapfile;CRITICAL;notify-service-by-email;CHECK_NRPE: Socket timeout after 10 seconds.
  2. [1461932418] SERVICE NOTIFICATION: nagiosadmin;adminserver;Disk;CRITICAL;notify-service-by-email;CHECK_NRPE: Socket timeout after 10 seconds.
  3.  
  4. # 'notify-host-by-email' command definition
  5. define command {
  6. command_name notify-host-by-email
  7. command_line /usr/bin/printf "%b" "Notification Type: $NOTIFICATIONTYPE$nHost: $HOSTNAME$nState: $HOSTSTATE$nAddress: $HOSTADDRESS$nInfo: $HOSTOUTPUT$nnDate/Time: $LONGDATETIME$n" | /usr/local/bin/mailsend.rb "***** Nagios Alert*****"
  8. }
  9.  
  10. # 'notify-service-by-email' command definition
  11. define command {
  12. command_name notify-service-by-email
  13. command_line /usr/bin/printf "%b" "Notification Type: $NOTIFICATIONTYPE$nHost: $HOSTNAME$nState: $HOSTSTATE$nAddress: $HOSTADDRESS$nInfo: $HOSTOUTPUT$nnDate/Time: $LONGDATETIME$n" | /usr/local/bin/mailsend.rb "***** Nagios Alert*****"
  14. }
  15.  
  16. define contact{
  17. contact_name nagiosadmin ; Short name of user
  18. use generic-contact ; Inherit default values from generic-contact template (defined above)
  19. alias Nagios Admin ; Full name of user
  20. service_notification_period 24x7
  21. host_notification_period 24x7
  22. service_notification_options w,u,c,r
  23. host_notification_options d,r
  24. service_notification_commands notify-service-by-email
  25. host_notification_commands notify-host-by-email
  26. email idontcare@examnple.org ;
  27. }
  28.  
  29. define contactgroup{
  30. contactgroup_name admins
  31. alias Nagios Administrators
  32. members nagiosadmin
  33. }
  34.  
  35. [1461935539.111737] [032.2] [pid=8391] ** Notifying contact 'nagiosadmin'
  36. [1461935539.111762] [032.2] [pid=8391] Raw notification command: /usr/local/bin/mailsend.rb "***** Nagios Alert*****" "Notification Type: $NOTIFICATIONTYPE$nHost: $HOSTNAME$nState: $HOSTSTATE$nAddress: $HOSTADDRESS$nInfo: $HOSTOUTPUT$nnDate/Time: $LONGDATETIME$"
  37. [1461935539.111799] [032.2] [pid=8391] Processed notification command: /usr/local/bin/mailsend.rb "***** Nagios Alert*****" "Notification Type: PROBLEMnHost: mysqlservernState: UPnAddress: 10.130.1.22nInfo: PING OK - Packet loss = 0%, RTA = 0.33 msnnDate/Time: Fri Apr 29 15:12:19 CEST 2016"
  38.  
  39. #!/usr/bin/env ruby
  40. require 'net/smtp'
  41. require 'logger'
  42.  
  43. require 'rubygems'
  44. require 'net-ldap'
  45. require '/home/user/lib/ntlm/smtp'
  46. logger = Logger.new('/var/log/sendEmail')
  47.  
  48. server = '10.130.1.3'
  49. port = 25 # or 25 - double check with your provider
  50. username = 'user'
  51. password = '****'
  52.  
  53. fromAddress = 'existingmail@existingdomain.de'
  54. toAddress = 'me@example.com'
  55. subject = ARGV[0]
  56. message = ARGV[1]
  57.  
  58. logger.info subject
  59. logger.info message
  60.  
  61. message_body = <<END_OF_EMAIL
  62. From: Nagios <#{fromAddress}>
  63. To: Logs <#{toAddress}>
  64. Subject: #{subject}
  65.  
  66. #{message}
  67. END_OF_EMAIL
  68.  
  69. smtp = Net::SMTP.new(server, port)
  70. smtp.start(server,username,password, :ntlm)
  71. smtp.send_message(message_body, fromAddress, toAddress)
  72.  
  73. nagios@background-server:/usr/local/bin$ whoami
  74. nagios
  75. nagios@background-server:/usr/local/bin$ ./mailsend.rb
  76. nagios@background-server:/usr/local/bin$
  77. nagios@background-server:/usr/local/bin$ ls -la mailsend.rb
  78. -rwxr-xr-x 1 nagios nagios 811 May 2 09:05 mailsend.rb
  79.  
  80. require 'ntlm/smtp'
  81.  
  82. $:.unshift File.dirname('/home/application/my_application/current/lib/ntlm')
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement