From 7d1ae6e557fe4aa37613a4fb929dfa41e34b065a Mon Sep 17 00:00:00 2001 From: i5513 Date: Mon, 14 Nov 2016 16:30:58 +0100 Subject: [PATCH 1/4] Add python 2.4 compatibility (for Centos 5) Manage exceptions like http://stackoverflow.com/a/12682585 tell. Nest try - catch to not use except / finally in the same sentence [https://docs.python.org/2.4/tut/node10.html] --- bin/check_apache | 29 ++++++++++++++++++----------- 1 file changed, 18 insertions(+), 11 deletions(-) diff --git a/bin/check_apache b/bin/check_apache index c4e6dbd..063dbaf 100755 --- a/bin/check_apache +++ b/bin/check_apache @@ -1,4 +1,5 @@ #!/usr/bin/python +# https://github.com/gpmidi/zabbix-apache-stats/blob/master/bin/check_apache """ Fetch Apache stats via mod_status and send to Zabbix By Paulson McIntyre @@ -43,7 +44,7 @@ def setLogLevel(loglevel): logger.setLevel(numeric_loglevel) log_handler = logging.handlers.SysLogHandler( address = '/dev/log' ) - #log_handler = logging.StreamHandler(sys.stdout) + # log_handler = logging.StreamHandler(sys.stdout) logger.addHandler( log_handler ) return logger @@ -94,14 +95,15 @@ def zabbix_sender(payload, agentconfig = None, zabbixserver = None, zabbixport = logger.error('must specify agent configuration or server name to call zabbix_sender with') try: - p = Popen(sender_command, stdout = PIPE, stdin = PIPE, stderr = PIPE) - out, err = p.communicate( input = payload ) - ret = p.wait() + try: + p = Popen(sender_command, stdout = PIPE, stdin = PIPE, stderr = PIPE) + out, err = p.communicate( input = payload ) + ret = p.wait() + except Exception: + t, e = sys.exc_info()[:2] + err = "%s\nFailed to execute: '%s'" % (e, " ".join(sender_command)) result = 1 - except Exception, e: - err = "%s\nFailed to execute: '%s'" % (e, " ".join(sender_command)) - finally: if ret != 0: raise Exception("error returned from %s! ret: %d, out: '%s', err: '%s'" % (sender_command[0], ret, out.strip('\n'), err.strip('\n'))) @@ -313,12 +315,14 @@ def main(): try: server_status = fetchURL(opts.url, user = opts.user, passwd = opts.passwd) - except Exception as e: + except Exception: + t, e = sys.exc_info()[:2] zbx_fail('failed to read server-status: %s' % e) try: data = parse( data = server_status, version = opts.statusvers ) - except Exception as e: + except Exception: + t, e = sys.exc_info()[:2] zbx_fail('failed to parse server-status: %s' % e) payload = "" @@ -333,7 +337,8 @@ def main(): payload = payload, agentconfig = opts.agentconfig, senderloc = opts.senderloc ) - except Exception as e: + except Exception: + t, e = sys.exc_info()[:2] zbx_fail('failed to send parsed data: %s' % e) else: # return value for apache.status item @@ -350,10 +355,12 @@ def main(): zabbixserver = opts.zabbixserver, zabbixport = opts.zabbixport, senderloc = opts.senderloc ) - except Exception as e: + except Exception: + t, e = sys.exc_info()[:2] zbx_fail('failed to send parsed data: %s' % e) if __name__ == "__main__": loglevel = 'debug' logger = setLogLevel(loglevel) main() + From 64cbeea11efbf8d736e80d2f425b0dc089423d0d Mon Sep 17 00:00:00 2001 From: i5513 Date: Mon, 14 Nov 2016 16:32:16 +0100 Subject: [PATCH 2/4] Template_App_Apache_Status translated to spanish Maintain Template group, and does not translate two item which I don't know how to say on spanish. --- conf/Template_App_Apache_Status-3.0.es.xml | 1172 ++++++++++++++++++++ 1 file changed, 1172 insertions(+) create mode 100644 conf/Template_App_Apache_Status-3.0.es.xml diff --git a/conf/Template_App_Apache_Status-3.0.es.xml b/conf/Template_App_Apache_Status-3.0.es.xml new file mode 100644 index 0000000..5f357fb --- /dev/null +++ b/conf/Template_App_Apache_Status-3.0.es.xml @@ -0,0 +1,1172 @@ + + + 3.0 + 2016-11-14T14:03:53Z + + + App Templates + + + Templates + + + + + + + + Apache - Estadísticas + 900 + 200 + 0.0000 + 100.0000 + 1 + 1 + 0 + 1 + 0 + 0.0000 + 0.0000 + 0 + 0 + 0 + 0 + + + 2 + 0 + 0000C8 + 0 + 2 + 0 + + Plantilla_Apache_Estado + apache[BytesPerSec] + + + + 3 + 0 + C800C8 + 0 + 2 + 0 + + Plantilla_Apache_Estado + apache[CPULoad] + + + + 0 + 0 + C80000 + 0 + 2 + 0 + + Plantilla_Apache_Estado + apache[BusyWorkers] + + + + 4 + 0 + 00C8C8 + 0 + 2 + 0 + + Plantilla_Apache_Estado + apache[ReqPerSec] + + + + 1 + 0 + 00C800 + 0 + 2 + 0 + + Plantilla_Apache_Estado + apache[BytesPerReq] + + + + + + Apache - Workers + 900 + 200 + 0.0000 + 100.0000 + 1 + 1 + 1 + 1 + 0 + 0.0000 + 0.0000 + 0 + 0 + 0 + 0 + + + 2 + 0 + 0000C8 + 0 + 2 + 0 + + Plantilla_Apache_Estado + apache[Gracefullyfinishing] + + + + 1 + 0 + 00C800 + 0 + 2 + 0 + + Plantilla_Apache_Estado + apache[DNSLookup] + + + + 3 + 0 + C800C8 + 0 + 2 + 0 + + Plantilla_Apache_Estado + apache[Idlecleanupofworker] + + + + 11 + 0 + 009696 + 0 + 2 + 0 + + Plantilla_Apache_Estado + apache[IdleWorkers] + + + + 0 + 0 + C80000 + 0 + 2 + 0 + + Plantilla_Apache_Estado + apache[Closingconnection] + + + + 9 + 0 + 000096 + 0 + 2 + 0 + + Plantilla_Apache_Estado + apache[Startingup] + + + + 4 + 0 + 00C8C8 + 0 + 2 + 0 + + Plantilla_Apache_Estado + apache[Keepaliveread] + + + + 5 + 0 + C8C800 + 0 + 2 + 0 + + Plantilla_Apache_Estado + apache[Logging] + + + + 10 + 0 + 960096 + 0 + 2 + 0 + + Plantilla_Apache_Estado + apache[WaitingforConnection] + + + + 8 + 0 + 009600 + 0 + 2 + 0 + + Plantilla_Apache_Estado + apache[SendingReply] + + + + 7 + 0 + 960000 + 0 + 2 + 0 + + Plantilla_Apache_Estado + apache[ReadingRequest] + + + + 6 + 0 + C8C8C8 + 0 + 2 + 0 + + Plantilla_Apache_Estado + apache[Openslotwithnocurrentprocess] + + + + + + + From 40499dfdf92a939d049f0de299ca3ac551490c69 Mon Sep 17 00:00:00 2001 From: i5513 Date: Mon, 14 Nov 2016 16:37:31 +0100 Subject: [PATCH 3/4] Add trigger triggered when apache is down --- conf/Template_App_Apache_Status-3.0.es.xml | 18 ++++++++++++++++++ conf/Template_App_Apache_Status-3.0.xml | 19 +++++++++++++++++++ 2 files changed, 37 insertions(+) diff --git a/conf/Template_App_Apache_Status-3.0.es.xml b/conf/Template_App_Apache_Status-3.0.es.xml index 5f357fb..dd6e4a2 100644 --- a/conf/Template_App_Apache_Status-3.0.es.xml +++ b/conf/Template_App_Apache_Status-3.0.es.xml @@ -922,6 +922,24 @@ + + + {Plantilla_Apache_Estado:apache.status.last()}=0 + 0 + + {HOST.NAME} Apache - Apache Caido + 0 + + + 0 + 2 + + 0 + 0 + + + + Apache - Estadísticas diff --git a/conf/Template_App_Apache_Status-3.0.xml b/conf/Template_App_Apache_Status-3.0.xml index 4ea16e2..102b5e3 100644 --- a/conf/Template_App_Apache_Status-3.0.xml +++ b/conf/Template_App_Apache_Status-3.0.xml @@ -922,6 +922,24 @@ + + + {Template_App_Apache_Status:apache.status.last()}=0 + 0 + + {HOST.NAME} Apache - Apache is Down + 0 + + + 0 + 2 + + 0 + 0 + + + + Apache Stats @@ -1169,3 +1187,4 @@ + From bc5741728aed78ab2a215aa90e87a22470b071c0 Mon Sep 17 00:00:00 2001 From: i5513 Date: Mon, 14 Nov 2016 16:42:58 +0100 Subject: [PATCH 4/4] Translated the description of Apache Status --- conf/Template_App_Apache_Status-3.0.es.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/conf/Template_App_Apache_Status-3.0.es.xml b/conf/Template_App_Apache_Status-3.0.es.xml index dd6e4a2..081c28c 100644 --- a/conf/Template_App_Apache_Status-3.0.es.xml +++ b/conf/Template_App_Apache_Status-3.0.es.xml @@ -358,7 +358,7 @@ - Item used to trigger zabbix trapper submission by agent. + Item usado para recopilar información a través de zabbix trappers. 0