]> git.uio.no Git - uio-zabbix.git/blobdiff - zabbix_get_logstash_stats.py
Bugfix: Fix at logstash overvåking feiler når en pipeline har blitt deaktivert. ...
[uio-zabbix.git] / zabbix_get_logstash_stats.py
index bde702f29dcd395eb568452f3e51e88684590f09..403fa00c387e6fb66b07b734f115f750f1a18b31 100755 (executable)
@@ -115,30 +115,32 @@ def generate_zabbix_sender_data(stats):
         pipelines_list = []
         
         for pipeline in stats['pipelines']:
-            
-            result +=  stats['host'] + " events.duration_in_millis[" + pipeline + "] " + str(stats['pipelines'][pipeline]['events']['duration_in_millis']) + "\n"
-            result +=  stats['host'] + " events.in[" + pipeline + "] " + str(stats['pipelines'][pipeline]['events']['in']) + "\n"
-            result +=  stats['host'] + " events.out[" + pipeline + "] " + str(stats['pipelines'][pipeline]['events']['out']) + "\n"
-            result +=  stats['host'] + " events.filtered[" + pipeline + "] " + str(stats['pipelines'][pipeline]['events']['filtered']) + "\n"
-            result +=  stats['host'] + " events.queue_push_duration_in_millis[" + pipeline + "] " + str(stats['pipelines'][pipeline]['events']['queue_push_duration_in_millis']) + "\n"
-            
-
-            if "capacity" in stats['pipelines'][pipeline]['queue']:
 
-                result +=  stats['host'] + " queue.capacity.max_queue_size_in_bytes[" + pipeline + "] " + str(stats['pipelines'][pipeline]['queue']['capacity']['max_queue_size_in_bytes']) + "\n"
-                result +=  stats['host'] + " queue.capacity.max_unread_events[" + pipeline + "] " + str(stats['pipelines'][pipeline]['queue']['capacity']['max_unread_events']) + "\n"
-                result +=  stats['host'] + " queue.capacity.page_capacity_in_bytes[" + pipeline + "] " + str(stats['pipelines'][pipeline]['queue']['capacity']['page_capacity_in_bytes']) + "\n"
-                result +=  stats['host'] + " queue.capacity.queue_size_in_bytes[" + pipeline + "] " + str(stats['pipelines'][pipeline]['queue']['capacity']['queue_size_in_bytes']) + "\n"
-                result +=  stats['host'] + " queue.events[" + pipeline + "] " + str(stats['pipelines'][pipeline]['queue']['events']) + "\n"
-                result +=  stats['host'] + " queue.type[" + pipeline + "] " + str(stats['pipelines'][pipeline]['queue']['type']) + "\n"
+            if stats['pipelines'][pipeline]['events'] != None:
 
-            else:
-                result +=  stats['host'] + " queue.type[" + pipeline + "] " + str(stats['pipelines'][pipeline]['queue']['type']) + "\n"
+                result +=  stats['host'] + " events.duration_in_millis[" + pipeline + "] " + str(stats['pipelines'][pipeline]['events']['duration_in_millis']) + "\n"
+                result +=  stats['host'] + " events.in[" + pipeline + "] " + str(stats['pipelines'][pipeline]['events']['in']) + "\n"
+                result +=  stats['host'] + " events.out[" + pipeline + "] " + str(stats['pipelines'][pipeline]['events']['out']) + "\n"
+                result +=  stats['host'] + " events.filtered[" + pipeline + "] " + str(stats['pipelines'][pipeline]['events']['filtered']) + "\n"
+                result +=  stats['host'] + " events.queue_push_duration_in_millis[" + pipeline + "] " + str(stats['pipelines'][pipeline]['events']['queue_push_duration_in_millis']) + "\n"
                 
-            result +=  stats['host'] + " reloads.failures[" + pipeline + "] " + str(stats['pipelines'][pipeline]['reloads']['failures']) + "\n"
-            result +=  stats['host'] + " reloads.last_failure_timestamp[" + pipeline + "] " + str(stats['pipelines'][pipeline]['reloads']['last_failure_timestamp']) + "\n"
-            result +=  stats['host'] + " reloads.last_success_timestamp[" + pipeline + "] " + str(stats['pipelines'][pipeline]['reloads']['last_success_timestamp']) + "\n"
-            result +=  stats['host'] + " reloads.successes[" + pipeline + "] " + str(stats['pipelines'][pipeline]['reloads']['successes']) + "\n"
+
+                if "capacity" in stats['pipelines'][pipeline]['queue']:
+
+                    result +=  stats['host'] + " queue.capacity.max_queue_size_in_bytes[" + pipeline + "] " + str(stats['pipelines'][pipeline]['queue']['capacity']['max_queue_size_in_bytes']) + "\n"
+                    result +=  stats['host'] + " queue.capacity.max_unread_events[" + pipeline + "] " + str(stats['pipelines'][pipeline]['queue']['capacity']['max_unread_events']) + "\n"
+                    result +=  stats['host'] + " queue.capacity.page_capacity_in_bytes[" + pipeline + "] " + str(stats['pipelines'][pipeline]['queue']['capacity']['page_capacity_in_bytes']) + "\n"
+                    result +=  stats['host'] + " queue.capacity.queue_size_in_bytes[" + pipeline + "] " + str(stats['pipelines'][pipeline]['queue']['capacity']['queue_size_in_bytes']) + "\n"
+                    result +=  stats['host'] + " queue.events[" + pipeline + "] " + str(stats['pipelines'][pipeline]['queue']['events']) + "\n"
+                    result +=  stats['host'] + " queue.type[" + pipeline + "] " + str(stats['pipelines'][pipeline]['queue']['type']) + "\n"
+                    
+                else:
+                    result +=  stats['host'] + " queue.type[" + pipeline + "] " + str(stats['pipelines'][pipeline]['queue']['type']) + "\n"
+                    
+                result +=  stats['host'] + " reloads.failures[" + pipeline + "] " + str(stats['pipelines'][pipeline]['reloads']['failures']) + "\n"
+                result +=  stats['host'] + " reloads.last_failure_timestamp[" + pipeline + "] " + str(stats['pipelines'][pipeline]['reloads']['last_failure_timestamp']) + "\n"
+                result +=  stats['host'] + " reloads.last_success_timestamp[" + pipeline + "] " + str(stats['pipelines'][pipeline]['reloads']['last_success_timestamp']) + "\n"
+                result +=  stats['host'] + " reloads.successes[" + pipeline + "] " + str(stats['pipelines'][pipeline]['reloads']['successes']) + "\n"
             
         return result
                            
@@ -168,15 +170,15 @@ if __name__ == '__main__':
         #
         
         for proxy in zabbix_proxy:
-
-            command = zabbix_sender + ' -z ' + proxy + ' -i ' + tmp_stat_file.name + ' > /dev/null 2>&1'
             
+            command = zabbix_sender + ' -z ' + proxy + ' -i ' + tmp_stat_file.name + ' > /dev/null 2>&1'
+                
             proc = subprocess.Popen([command],shell=True)
             proc.wait()
-        
+            
             if proc.returncode == 0:
                 break
-            
+        
         # Delete temp file with zabbix_sender data
         os.remove(tmp_stat_file.name)