Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- [1461932408] SERVICE NOTIFICATION: nagiosadmin;appserver;Swapfile;CRITICAL;notify-service-by-email;CHECK_NRPE: Socket timeout after 10 seconds.
- [1461932418] SERVICE NOTIFICATION: nagiosadmin;adminserver;Disk;CRITICAL;notify-service-by-email;CHECK_NRPE: Socket timeout after 10 seconds.
- # 'notify-host-by-email' command definition
- define command {
- command_name notify-host-by-email
- 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*****"
- }
- # 'notify-service-by-email' command definition
- define command {
- command_name notify-service-by-email
- 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*****"
- }
- define contact{
- contact_name nagiosadmin ; Short name of user
- use generic-contact ; Inherit default values from generic-contact template (defined above)
- alias Nagios Admin ; Full name of user
- service_notification_period 24x7
- host_notification_period 24x7
- service_notification_options w,u,c,r
- host_notification_options d,r
- service_notification_commands notify-service-by-email
- host_notification_commands notify-host-by-email
- email idontcare@examnple.org ;
- }
- define contactgroup{
- contactgroup_name admins
- alias Nagios Administrators
- members nagiosadmin
- }
- [1461935539.111737] [032.2] [pid=8391] ** Notifying contact 'nagiosadmin'
- [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$"
- [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"
- #!/usr/bin/env ruby
- require 'net/smtp'
- require 'logger'
- require 'rubygems'
- require 'net-ldap'
- require '/home/user/lib/ntlm/smtp'
- logger = Logger.new('/var/log/sendEmail')
- server = '10.130.1.3'
- port = 25 # or 25 - double check with your provider
- username = 'user'
- password = '****'
- fromAddress = 'existingmail@existingdomain.de'
- toAddress = 'me@example.com'
- subject = ARGV[0]
- message = ARGV[1]
- logger.info subject
- logger.info message
- message_body = <<END_OF_EMAIL
- From: Nagios <#{fromAddress}>
- To: Logs <#{toAddress}>
- Subject: #{subject}
- #{message}
- END_OF_EMAIL
- smtp = Net::SMTP.new(server, port)
- smtp.start(server,username,password, :ntlm)
- smtp.send_message(message_body, fromAddress, toAddress)
- nagios@background-server:/usr/local/bin$ whoami
- nagios
- nagios@background-server:/usr/local/bin$ ./mailsend.rb
- nagios@background-server:/usr/local/bin$
- nagios@background-server:/usr/local/bin$ ls -la mailsend.rb
- -rwxr-xr-x 1 nagios nagios 811 May 2 09:05 mailsend.rb
- require 'ntlm/smtp'
- $:.unshift File.dirname('/home/application/my_application/current/lib/ntlm')
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement