From 67b4dba32590e775f958d27e9e67af455ce1b0f8 Mon Sep 17 00:00:00 2001 From: linggao Date: Mon, 31 Mar 2008 15:57:15 +0000 Subject: [PATCH] added code the create mail aliase for trap handler in snmp.pm git-svn-id: https://svn.code.sf.net/p/xcat/code/xcat-core/trunk@947 8638fb3e-16cb-4fca-ae20-7b5d299a9bcd --- .../lib/xcat/monitoring/snmpmon.pm | 33 +++++++++++++++++++ 1 file changed, 33 insertions(+) diff --git a/xCAT-server-2.0/lib/xcat/monitoring/snmpmon.pm b/xCAT-server-2.0/lib/xcat/monitoring/snmpmon.pm index 9c308608e..cdaf9fc36 100644 --- a/xCAT-server-2.0/lib/xcat/monitoring/snmpmon.pm +++ b/xCAT-server-2.0/lib/xcat/monitoring/snmpmon.pm @@ -68,6 +68,9 @@ sub start { #enable MMAs if any configMPA(1); + #configure mail to enabling receiving mails from trap handler + configMail(); + return (0, "started") } @@ -257,6 +260,7 @@ sub configMPA { return ($ret_val, $ret_text); } + #-------------------------------------------------------------------------------- =head3 configSNMP This function puts xcat_traphanlder into the snmptrapd.conf file and @@ -341,6 +345,35 @@ sub configSNMP { return (0, "started"); } +#-------------------------------------------------------------------------------- +=head3 configMail + This function adds a "alerts" mail aliase so that the mail notification + from the trap handler can be received. It the alerts already exists, this + function does nothing. + TODO: configure mail servers on MS to forward mails to MS + Arguments: + none + Returns: + (return code, message) +=cut +#-------------------------------------------------------------------------------- +sub configMail { + #check if "alerts" is in the /etc/aliases file + if (-f "/etc/aliases"){ + # if the file exists, check if alerts is in + `/bin/grep -e ^alerts /etc/aliases > /dev/null`; + if ($? ==0) { return (0, "") }; + } + + #make a alerts aliase, forwarding the mail to the root of local host. + `echo "alerts: root" >> /etc/aliases`; + + #make it effective + `newaliases`; + + return (0, ""); +} + #-------------------------------------------------------------------------------- =head3 stop