]> xenbits.xensource.com Git - xcp/xen-api.git/commitdiff
CP-1799: update email-alert mechanism to use email info from VMPP instead of pool
authorMarcus Granado <marcus.granado@eu.citrix.com>
Mon, 23 Aug 2010 14:54:36 +0000 (15:54 +0100)
committerMarcus Granado <marcus.granado@eu.citrix.com>
Mon, 23 Aug 2010 14:54:36 +0000 (15:54 +0100)
Signed-off-by: Marcus Granado <marcus.granado@eu.citrix.com>
ocaml/client_records/records.ml
ocaml/idl/datamodel.ml
ocaml/xapi/xapi_message.ml
scripts/mail-alarm

index ed161840d90a37115339ab8439b92521acf7586a..3ea168a78a8fbe0aa1dd1801819513f69fad1a40 100644 (file)
@@ -194,7 +194,7 @@ let message_record rpc session_id message =
        make_field ~name:"uuid"         ~get:(fun () -> (x ()).API.message_uuid) ();
        make_field ~name:"name"         ~get:(fun () -> (x ()).API.message_name) ();
        make_field ~name:"priority"     ~get:(fun () -> Int64.to_string (x ()).API.message_priority) ();
-       make_field ~name:"class"        ~get:(fun () -> match (x ()).API.message_cls with `VM -> "VM" | `Host -> "Host" | `SR -> "SR" | `Pool -> "Pool") ();
+       make_field ~name:"class"        ~get:(fun () -> match (x ()).API.message_cls with `VM -> "VM" | `Host -> "Host" | `SR -> "SR" | `Pool -> "Pool" | `VMPP -> "VMPP") ();
        make_field ~name:"obj-uuid"     ~get:(fun () -> (x ()).API.message_obj_uuid) ();
        make_field ~name:"timestamp"    ~get:(fun () -> Date.to_string (x ()).API.message_timestamp) ();
        make_field ~name:"body"         ~get:(fun () -> (x ()).API.message_body) ();
index 8a612abb96eecf2361d6b739f9eea42e249b525c..7dd34671db62d49936b5e6d4683dc6770f970fd8 100644 (file)
@@ -6049,7 +6049,9 @@ let message =
     Enum ("cls", [ "VM", "VM";
                    "Host", "Host";
                   "SR", "SR";
-                  "Pool","Pool";])
+                  "Pool","Pool";
+       "VMPP","VMPP";
+    ])
   in
   let create = call
     ~name:"create"
index 6b1c4672da85f53efc47727474239225a1e2c879..00af3d03d5d1d0561bb5a08169f1aed1e703ab02 100644 (file)
@@ -41,7 +41,8 @@ let class_to_string cls =
     | `VM -> "VM" 
     | `Host -> "Host" 
     | `SR -> "SR" 
-    | `Pool -> "Pool" 
+    | `Pool -> "Pool"
+    | `VMPP -> "VMPP" 
     | _ -> "unknown"
 
 let string_to_class str = 
@@ -50,6 +51,7 @@ let string_to_class str =
     | "Host" -> `Host
     | "SR" -> `SR
     | "Pool" -> `Pool
+    | "VMPP" -> `VMPP
     | _ -> failwith "Bad type"
 
 (* We use the timestamp to name the file. For consistency, use this function *)
@@ -148,7 +150,9 @@ let check_uuid ~__context ~cls ~uuid =
       | `VM -> ignore(Db.VM.get_by_uuid ~__context ~uuid)
       | `Host -> ignore(Db.Host.get_by_uuid ~__context ~uuid)
       | `SR -> ignore(Db.SR.get_by_uuid ~__context ~uuid)
-      | `Pool -> ignore(Db.Pool.get_by_uuid ~__context ~uuid));
+      | `Pool -> ignore(Db.Pool.get_by_uuid ~__context ~uuid)
+      | `VMPP -> ignore(Db.VMPP.get_by_uuid ~__context ~uuid)
+    );
     true
   with _ -> 
     false
index cf65b667e8601b44b2cbc92f76dd149e73f0cfa2..1b3f97f2bca9e78ba4c1734a7a0dc6d6872b8422 100755 (executable)
@@ -26,13 +26,15 @@ mailhub=@MAILHUB@
 FromLineOverride=YES
 """
 
+ma_username="__dom0__mail_alarm"
+
 def log_err(err):
     print >>sys.stderr, err
     syslog.syslog(syslog.LOG_USER | syslog.LOG_ERR, "%s: %s" % (sys.argv[0], err))
 
 def get_pool_name():
     session = XenAPI.xapi_local()
-    session.xenapi.login_with_password("", "")
+    session.xenapi.login_with_password(ma_username, "")
     try:
         opaque_ref = session.xenapi.pool.get_all()[0]
         pool_name = session.xenapi.pool.get_name_label(opaque_ref)
@@ -47,16 +49,35 @@ def get_pool_name():
 
 def get_pool_other_config():
     session = XenAPI.xapi_local()
-    session.xenapi.login_with_password("", "")
+    session.xenapi.login_with_password(ma_username, "")
     try:
         opaque_ref = session.xenapi.pool.get_all()[0]
         return session.xenapi.pool.get_other_config(opaque_ref)
     finally:
         session.xenapi.session.logout()
 
+def get_vmpp_alarm_config(uuid):
+    session = XenAPI.xapi_local()
+    session.xenapi.login_with_password(ma_username, "")
+    try:
+        opaque_ref = session.xenapi.VMPP.get_by_uuid(uuid)
+        vmpp_alarm_config = session.xenapi.VMPP.get_alarm_config(opaque_ref)
+        vmpp_is_alarm_enabled = session.xenapi.VMPP.get_is_alarm_enabled(opaque_ref)
+        try:
+            vmpp_smtp_server=vmpp_alarm_config['smtp_server']
+            vmpp_smtp_port=vmpp_alarm_config['smtp_port']
+            vmpp_email_address=vmpp_alarm_config['email_address']
+        except:
+            log_err("VMPP uuid=%s: not sending email alert due to incomplete configuration" % uuid)
+            sys.exit(1)
+        other_config = {'ssmtp-mailhub':"%s %s" % (vmpp_smtp_server,vmpp_smtp_port),'mail-destination':vmpp_email_address}
+        return vmpp_is_alarm_enabled,other_config
+    finally:
+        session.xenapi.session.logout()
+
 def get_VM_params(uuid):
     session = XenAPI.xapi_local()
-    session.xenapi.login_with_password("", "")
+    session.xenapi.login_with_password(ma_username, "")
     try:
         try:
             opaque_ref = session.xenapi.VM.get_by_uuid(uuid)
@@ -68,7 +89,7 @@ def get_VM_params(uuid):
 
 def get_host_params(uuid):
     session = XenAPI.xapi_local()
-    session.xenapi.login_with_password("", "")
+    session.xenapi.login_with_password(ma_username, "")
     try:
         try:
             opaque_ref = session.xenapi.host.get_by_uuid(uuid)
@@ -290,6 +311,12 @@ class XapiMessage:
     def get_priority(self):
         return int(self.priority)
 
+    def get_cls(self):
+        return self.cls
+
+    def get_obj_uuid(self):
+        return self.obj_uuid
+
     def __get_email_text_generator(self):
         """Returns an EmailTextGenerator object appropriate to this XapiMessage or None if none found"""
         if hasattr(self,'cached_etg'):
@@ -371,11 +398,18 @@ def main():
     # We only mail messages with level min_priority or higher
     if msg.get_priority() < min_priority:
         return 0
-    
-    config = get_config_file()
+
+    if msg.get_cls() == "VMPP":
+        config = default_config
+        vmpp_is_alarm_enabled, other_config = get_vmpp_alarm_config(msg.get_obj_uuid())
+        if not vmpp_is_alarm_enabled:
+          return 0
+    else:        
+        config = get_config_file()
+
     search_replace = get_search_replace(other_config)
     destination = get_destination(other_config)
-    
+
     if not destination:
         log_err("pool:other-config:mail-destination not specified")
         return 1