EMS doesn’t allow to edit sender email address. All events are always sent out with sender id as root@hostname. Here is small script to change it.
Requirement :
Normally in Event monitoring system ( EMS ) on HPUX send an emails with sender id as root@hostname. Many organizations email servers dont allow such email address in sender field. We need generic email id in sender field when EMS shoots an alert email something like notification@xyz.com
Workaround :
There is no provision to change this email id anywhere in HPUX or EMS configurations. You can use below workaround which works perfectly without any issues.
Step 1 :
Make sure you have valid email address (like notification@xyz.com) for your logged in account which works. Send a test email from server to verify using below command
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
|
# echo test |/usr/sbin/sendmail -v receiver_id@xyz.com
receiver_id@xyz.com... Connecting to smtpserver.xyz.com via relay...
220 smtpserver.xyz.com ESMTP Postfix
>>> EHLO xyz.com
250-smtpserver.xyz.com
250-PIPELINING
250-SIZE 25600000
250-VRFY
250-ETRN
250-ENHANCEDSTATUSCODES
250-8BITMIME
250 DSN
>>> MAIL From:<root@xyz.com> SIZE=5
250 2.1.0 Ok
>>> RCPT To:<receiver_id@xyz.com>
>>> DATA
250 2.1.5 Ok
354 End data with <CR><LF>.<CR><LF>
>>> .
250 2.0.0 Ok: queued as 46466822F2
receiver_id@xyz.com... Sent (Ok: queued as 46466822F2)
Closing connection to smtpserver.xyz.com
>>> QUIT
221 2.0.0 Bye
|
Step 2 :
Setup crontab for above logged in account (for which email tested) which will execute EMS log scanner script every 30 minutes. As per your convenience you can even schedule it to run every 10 mins or even lower.
|
00,30 * * * * /scripts/ems_monitor.sh
|
Step 3:
Script code is as below.
| # Script to scan EMS log file and email alert if any |
| # Author : Shrikant Lavhate |
| #! /bin/bash |
| if [ -f "/logs/event_monitor.log" ] |
| then |
| : |
| else |
| cp -p /var/opt/resmon/log/event.log /logs/event_monitor.log |
| fi |
| diff /logs/event_monitor.log /var/opt/resmon/log/event.log /logs/logfile_difference |
| if [ -s "/logs/logfile_difference" ] |
| then |
| cat /logs/logfile_difference | grep '^'|cut -c 2- | mailx -s "EMS monitor alert from `hostname`" receiver_id@xyz.com |
| fi |
| cp -p /var/opt/resmon/log/event.log /logs/event_monitor.log |
Step 4:
Now you can test the script by generating test events in EMS. Generate test event with send_test_event command.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
|
# send_test_event -v -a disk_em
Finding resource name associated with monitor disk_em.
Found resource name /storage/events/disks/default
associated with monitor disk_em.
Creating test file /var/stm/config/tools/monitor/disk_em.test
for monitor disk_em.
Making test file /var/stm/config/tools/monitor/disk_em.test
for monitor disk_em
indicate send test event for all resources.
Performing resls on resource name /storage/events/disks/default
for monitor disk_em to cause generation of test event.
Contacting Registrar on aprss006
NAME: /storage/events/disks/default
DESCRIPTION: Disk Event Monitor
This resource monitors events for stand-alone disk drives. Event
monitoring requests are created using the Monitoring Request
Manager. Monitoring requests to detect changes in device status are
created using the Peripheral Status Monitor (psmmon(1m)) and Event
Monitoring Service (EMS).
For more information see the monitor man page, (disk_em(1m)).
TYPE: /storage/events/disks/default is a Resource Class.
There are 2 resources configured below /storage/events/disks/default:
Resource Class
/storage/events/disks/default/64000_0xfa00_0x0
/storage/events/disks/default/64000_0xfa00_0x35
|
You will receive test events from admin@hostname email id which is normal. Now run above script and you will receive same email with sender id as notification@xyz.com !!
I have tested this script and it works flawlessly. Please leave comments below if its helpful to you too.
No comments:
Post a Comment