Wallace Daniel has uploaded a new change for review.

Change subject: Adding support for ovirt-ha-agent status
......................................................................

Adding support for ovirt-ha-agent status

When log collector is run, it now checks each host for the
ovirt-ha-agent status. If no host has this installed, then nothing ends
up logged. Any host that has this service running or stopped will have the
hostname and agent service status logged in the 'ha_hosts.txt' file
under the log-collector-data directory. The service status is
checked with the 'service ovirt-ha-agent status 2>&1 || true' command
and stdout is logged to the ha_hosts.txt file. The 'service' command
was chosen instead of 'rpm' so that agent status is found in addition
to just being installed.

Change-Id: I43c14112df2e15289f5aac1c302eeafc011ed9ae
Signed-off-by: Wallace Daniel <wallace.dani...@gmail.com>
---
M src/__main__.py
1 file changed, 43 insertions(+), 1 deletion(-)


  git pull ssh://gerrit.ovirt.org:29418/ovirt-log-collector 
refs/changes/69/31269/1

diff --git a/src/__main__.py b/src/__main__.py
index a73dbf2..223be74 100755
--- a/src/__main__.py
+++ b/src/__main__.py
@@ -49,6 +49,7 @@
 
 DEFAULT_SSH_USER = 'root'
 DEFAULT_TIME_SHIFT_FILE = 'time_diff.txt'
+DEFAULT_HE_FILE = 'ha_hosts.txt'
 PGPASS_FILE_ADMIN_LINE = "DB ADMIN credentials"
 DEFAULT_SCRATCH_DIR = None  # Will be initialized by __main__
 SSH_SERVER_ALIVE_INTERVAL = 600
@@ -601,17 +602,21 @@
         'Engine Time',
         'Clock Drift Between Engine and Node'
     )
+    HE_LIST_FORMAT = "%-15s: %-14s\n"
+    HE_LIST_HEADER = HE_LIST_FORMAT % ('Hostname', 'Service Status')
 
     def __init__(self,
                  hostname,
                  configuration=None,
                  semaphore=None,
                  queue=None,
+                 ha_list=None,
                  gluster_enabled=False,
                  **kwargs):
         super(HyperVisorData, self).__init__(hostname, configuration)
         self.semaphore = semaphore
         self.queue = queue
+        self.ha_list = ha_list
         self.gluster_enabled = gluster_enabled
 
     def prep(self):
@@ -669,6 +674,14 @@
                 "-%s" % (l_time - h_time)
             )
             self.queue.append(tmp)
+
+    def check_ha_host(self, stdout):
+        agent_check = stdout
+        # If unrecognized, not installed
+        if not 'unrecognized' in agent_check:
+            self.ha_list.append(self.hostname + ": " + agent_check)
+        else:
+            pass
 
     def sosreport(self):
         # Add gluster to the list of sosreports required if gluster is enabled
@@ -748,6 +761,13 @@
                 self.get_time_diff(stdout)
             except ValueError, e:
                 logging.debug("get_time_diff: " + str(e))
+
+            stdout = self.caller.call('%(ssh_cmd)s "service ovirt-ha-agent 
status 2>&1 || true"')
+            try:
+                self.check_ha_host(stdout)
+            except ValueError as e:
+                logging.debug("check_ha_host: " + str(e))
+
         except Exception, e:
             ExitCodes.exit_code = ExitCodes.WARN
             logging.error(
@@ -1049,6 +1069,22 @@
             for record in queue:
                 fd.write(record + "\n")
 
+    def write_ha_list(self, ha_list):
+        local_scratch_dir = self.conf.get("local_scratch_dir")
+        filepath = os.path.join(local_scratch_dir, DEFAULT_HE_FILE)
+        with open(filepath, "w") as fd:
+            hostname_length = 5
+            for record in ha_list:
+                if len(record.split(":")[0]) > hostname_length:
+                    hostname_length = len(record.split(":")[0])
+
+            HE_LIST_FORMAT = "%-"+str(hostname_length)+"s: %-14s\n"
+            HE_LIST_HEADER = HE_LIST_FORMAT % ('Hostname', 'Service Status')
+
+            fd.write(HE_LIST_HEADER + "\n")
+            for record in ha_list:
+                fd.write(record + "\n")
+
     def _get_hypervisors_from_api(self):
         if not self.conf:
             raise Exception("No configuration.")
@@ -1278,7 +1314,7 @@
             # max_connections may be defined as a string via a .rc file
             sem = threading.Semaphore(int(max_connections))
             time_diff_queue = deque()
-
+            he_list_queue = deque()
             threads = []
 
             for datacenter, cluster, host in hosts:
@@ -1288,6 +1324,7 @@
                     configuration=self.conf,
                     semaphore=sem,
                     queue=time_diff_queue,
+                    ha_list=he_list_queue,
                     gluster_enabled=cluster.gluster_enabled
                 )
                 thread = threading.Thread(target=collector.run)
@@ -1298,6 +1335,11 @@
                 thread.join()
 
             self.write_time_diff(time_diff_queue)
+            if len(he_list_queue) > 0:
+                self.write_ha_list(he_list_queue)
+            else:
+                logging.info("No ovirt-ha-agent services detected on hosts, 
not writing ha_hosts.txt file.")
+
 
     def get_postgres_data(self):
         if self.conf.get("no_postgresql") is False:


-- 
To view, visit http://gerrit.ovirt.org/31269
To unsubscribe, visit http://gerrit.ovirt.org/settings

Gerrit-MessageType: newchange
Gerrit-Change-Id: I43c14112df2e15289f5aac1c302eeafc011ed9ae
Gerrit-PatchSet: 1
Gerrit-Project: ovirt-log-collector
Gerrit-Branch: master
Gerrit-Owner: Wallace Daniel <wallace.dani...@gmail.com>
_______________________________________________
Engine-patches mailing list
Engine-patches@ovirt.org
http://lists.ovirt.org/mailman/listinfo/engine-patches

Reply via email to