[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Xen-API] [PATCH 02 of 21] CP-1799: update email-alert mechanism to use email info from VMPP instead of pool



 ocaml/client_records/records.ml |   2 +-
 ocaml/idl/datamodel.ml          |   4 ++-
 ocaml/xapi/xapi_message.ml      |   8 +++++-
 scripts/mail-alarm              |  48 +++++++++++++++++++++++++++++++++++-----
 4 files changed, 51 insertions(+), 11 deletions(-)


# HG changeset patch
# User Marcus Granado <marcus.granado@xxxxxxxxxx>
# Date 1282322886 -3600
# Node ID 2061d0df12850f6192ee5d702d2fbdb774bbb47e
# Parent  1f0e971a9665a927a9424d8926c3c9d49147eee9
CP-1799: update email-alert mechanism to use email info from VMPP instead of 
pool

Signed-off-by: Marcus Granado <marcus.granado@xxxxxxxxxxxxx>

diff -r 1f0e971a9665 -r 2061d0df1285 ocaml/client_records/records.ml
--- a/ocaml/client_records/records.ml
+++ b/ocaml/client_records/records.ml
@@ -194,7 +194,7 @@
        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) ();
diff -r 1f0e971a9665 -r 2061d0df1285 ocaml/idl/datamodel.ml
--- a/ocaml/idl/datamodel.ml
+++ b/ocaml/idl/datamodel.ml
@@ -6049,7 +6049,9 @@
     Enum ("cls", [ "VM", "VM";
                    "Host", "Host";
                   "SR", "SR";
-                  "Pool","Pool";])
+                  "Pool","Pool";
+       "VMPP","VMPP";
+    ])
   in
   let create = call
     ~name:"create"
diff -r 1f0e971a9665 -r 2061d0df1285 ocaml/xapi/xapi_message.ml
--- a/ocaml/xapi/xapi_message.ml
+++ b/ocaml/xapi/xapi_message.ml
@@ -41,7 +41,8 @@
     | `VM -> "VM" 
     | `Host -> "Host" 
     | `SR -> "SR" 
-    | `Pool -> "Pool" 
+    | `Pool -> "Pool"
+    | `VMPP -> "VMPP" 
     | _ -> "unknown"
 
 let string_to_class str = 
@@ -50,6 +51,7 @@
     | "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 @@
       | `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
diff -r 1f0e971a9665 -r 2061d0df1285 scripts/mail-alarm
--- a/scripts/mail-alarm
+++ b/scripts/mail-alarm
@@ -26,13 +26,15 @@
 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_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_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 @@
     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 @@
     # 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

Attachment: xen-api.hg-02.patch
Description: Text Data

_______________________________________________
xen-api mailing list
xen-api@xxxxxxxxxxxxxxxxxxx
http://lists.xensource.com/mailman/listinfo/xen-api

 


Rackspace

Lists.xenproject.org is hosted with RackSpace, monitoring our
servers 24x7x365 and backed by RackSpace's Fanatical Support®.