Skip to content

Instantly share code, notes, and snippets.

@strangeman
Created October 7, 2013 23:43
Show Gist options
  • Save strangeman/6876976 to your computer and use it in GitHub Desktop.
Save strangeman/6876976 to your computer and use it in GitHub Desktop.
Monitoring Apache
<?xml version="1.0" encoding="UTF-8"?>
<zabbix_export>
<version>2.0</version>
<date>2013-10-07T23:02:04Z</date>
<groups>
<group>
<name>Templates</name>
</group>
<group>
<name>Web Server</name>
</group>
</groups>
<templates>
<template>
<template>Template_App_Apache_Stats</template>
<name>Template_App_Apache_Stats</name>
<groups>
<group>
<name>Templates</name>
</group>
<group>
<name>Web Server</name>
</group>
</groups>
<applications>
<application>
<name>Apache Stats</name>
</application>
<application>
<name>Apache Worker</name>
</application>
</applications>
<items>
<item>
<name>Apache - Busy Workers</name>
<type>7</type>
<snmp_community>public</snmp_community>
<multiplier>0</multiplier>
<snmp_oid>interfaces.ifTable.ifEntry.ifInOctets.1</snmp_oid>
<key>apache[localhost,BusyWorkers]</key>
<delay>60</delay>
<history>365</history>
<trends>9999</trends>
<status>0</status>
<value_type>3</value_type>
<allowed_hosts/>
<units>Workers</units>
<delta>0</delta>
<snmpv3_securityname/>
<snmpv3_securitylevel>0</snmpv3_securitylevel>
<snmpv3_authpassphrase/>
<snmpv3_privpassphrase/>
<formula>1</formula>
<delay_flex/>
<params/>
<ipmi_sensor/>
<data_type>0</data_type>
<authtype>0</authtype>
<username/>
<password/>
<publickey/>
<privatekey/>
<port/>
<description/>
<inventory_link>0</inventory_link>
<applications>
<application>
<name>Apache Worker</name>
</application>
</applications>
<valuemap/>
</item>
<item>
<name>Apache - Bytes Per Request</name>
<type>7</type>
<snmp_community>public</snmp_community>
<multiplier>0</multiplier>
<snmp_oid>interfaces.ifTable.ifEntry.ifInOctets.1</snmp_oid>
<key>apache[localhost,BytesPerReq]</key>
<delay>60</delay>
<history>365</history>
<trends>9999</trends>
<status>0</status>
<value_type>0</value_type>
<allowed_hosts/>
<units>b</units>
<delta>0</delta>
<snmpv3_securityname/>
<snmpv3_securitylevel>0</snmpv3_securitylevel>
<snmpv3_authpassphrase/>
<snmpv3_privpassphrase/>
<formula>1</formula>
<delay_flex/>
<params/>
<ipmi_sensor/>
<data_type>0</data_type>
<authtype>0</authtype>
<username/>
<password/>
<publickey/>
<privatekey/>
<port/>
<description/>
<inventory_link>0</inventory_link>
<applications>
<application>
<name>Apache Stats</name>
</application>
</applications>
<valuemap/>
</item>
<item>
<name>Apache - Bytes Per Second</name>
<type>7</type>
<snmp_community>public</snmp_community>
<multiplier>0</multiplier>
<snmp_oid>interfaces.ifTable.ifEntry.ifInOctets.1</snmp_oid>
<key>apache[localhost,BytesPerSec]</key>
<delay>60</delay>
<history>365</history>
<trends>9999</trends>
<status>0</status>
<value_type>0</value_type>
<allowed_hosts/>
<units>b/s</units>
<delta>0</delta>
<snmpv3_securityname/>
<snmpv3_securitylevel>0</snmpv3_securitylevel>
<snmpv3_authpassphrase/>
<snmpv3_privpassphrase/>
<formula>1</formula>
<delay_flex/>
<params/>
<ipmi_sensor/>
<data_type>0</data_type>
<authtype>0</authtype>
<username/>
<password/>
<publickey/>
<privatekey/>
<port/>
<description/>
<inventory_link>0</inventory_link>
<applications>
<application>
<name>Apache Stats</name>
</application>
</applications>
<valuemap/>
</item>
<item>
<name>Apache - CPU Load</name>
<type>7</type>
<snmp_community>public</snmp_community>
<multiplier>0</multiplier>
<snmp_oid>interfaces.ifTable.ifEntry.ifInOctets.1</snmp_oid>
<key>apache[localhost,CPULoad]</key>
<delay>60</delay>
<history>365</history>
<trends>9999</trends>
<status>0</status>
<value_type>0</value_type>
<allowed_hosts/>
<units/>
<delta>0</delta>
<snmpv3_securityname/>
<snmpv3_securitylevel>0</snmpv3_securitylevel>
<snmpv3_authpassphrase/>
<snmpv3_privpassphrase/>
<formula>1</formula>
<delay_flex/>
<params/>
<ipmi_sensor/>
<data_type>0</data_type>
<authtype>0</authtype>
<username/>
<password/>
<publickey/>
<privatekey/>
<port/>
<description/>
<inventory_link>0</inventory_link>
<applications>
<application>
<name>Apache Stats</name>
</application>
</applications>
<valuemap/>
</item>
<item>
<name>Apache - Idle Workers</name>
<type>7</type>
<snmp_community>public</snmp_community>
<multiplier>0</multiplier>
<snmp_oid>interfaces.ifTable.ifEntry.ifInOctets.1</snmp_oid>
<key>apache[localhost,IdleWorkers]</key>
<delay>60</delay>
<history>365</history>
<trends>9999</trends>
<status>0</status>
<value_type>3</value_type>
<allowed_hosts/>
<units>Workers</units>
<delta>0</delta>
<snmpv3_securityname/>
<snmpv3_securitylevel>0</snmpv3_securitylevel>
<snmpv3_authpassphrase/>
<snmpv3_privpassphrase/>
<formula>1</formula>
<delay_flex/>
<params/>
<ipmi_sensor/>
<data_type>0</data_type>
<authtype>0</authtype>
<username/>
<password/>
<publickey/>
<privatekey/>
<port/>
<description/>
<inventory_link>0</inventory_link>
<applications>
<application>
<name>Apache Stats</name>
</application>
</applications>
<valuemap/>
</item>
<item>
<name>Apache - Requests Per Second</name>
<type>7</type>
<snmp_community>public</snmp_community>
<multiplier>0</multiplier>
<snmp_oid>interfaces.ifTable.ifEntry.ifInOctets.1</snmp_oid>
<key>apache[localhost,ReqPerSec]</key>
<delay>60</delay>
<history>365</history>
<trends>9999</trends>
<status>0</status>
<value_type>0</value_type>
<allowed_hosts/>
<units>r/s</units>
<delta>0</delta>
<snmpv3_securityname/>
<snmpv3_securitylevel>0</snmpv3_securitylevel>
<snmpv3_authpassphrase/>
<snmpv3_privpassphrase/>
<formula>1</formula>
<delay_flex/>
<params/>
<ipmi_sensor/>
<data_type>0</data_type>
<authtype>0</authtype>
<username/>
<password/>
<publickey/>
<privatekey/>
<port/>
<description/>
<inventory_link>0</inventory_link>
<applications>
<application>
<name>Apache Stats</name>
</application>
</applications>
<valuemap/>
</item>
<item>
<name>Apache - Total Accesses</name>
<type>7</type>
<snmp_community>public</snmp_community>
<multiplier>0</multiplier>
<snmp_oid>interfaces.ifTable.ifEntry.ifInOctets.1</snmp_oid>
<key>apache[localhost,TotalAccesses]</key>
<delay>60</delay>
<history>365</history>
<trends>9999</trends>
<status>0</status>
<value_type>3</value_type>
<allowed_hosts/>
<units/>
<delta>0</delta>
<snmpv3_securityname/>
<snmpv3_securitylevel>0</snmpv3_securitylevel>
<snmpv3_authpassphrase/>
<snmpv3_privpassphrase/>
<formula>1</formula>
<delay_flex/>
<params/>
<ipmi_sensor/>
<data_type>0</data_type>
<authtype>0</authtype>
<username/>
<password/>
<publickey/>
<privatekey/>
<port/>
<description/>
<inventory_link>0</inventory_link>
<applications>
<application>
<name>Apache Stats</name>
</application>
</applications>
<valuemap/>
</item>
<item>
<name>Apache - Total Data Transfer</name>
<type>7</type>
<snmp_community>public</snmp_community>
<multiplier>1</multiplier>
<snmp_oid>interfaces.ifTable.ifEntry.ifInOctets.1</snmp_oid>
<key>apache[localhost,TotalkBytes]</key>
<delay>60</delay>
<history>365</history>
<trends>9999</trends>
<status>0</status>
<value_type>3</value_type>
<allowed_hosts/>
<units>b</units>
<delta>0</delta>
<snmpv3_securityname/>
<snmpv3_securitylevel>0</snmpv3_securitylevel>
<snmpv3_authpassphrase/>
<snmpv3_privpassphrase/>
<formula>1024</formula>
<delay_flex/>
<params/>
<ipmi_sensor/>
<data_type>0</data_type>
<authtype>0</authtype>
<username/>
<password/>
<publickey/>
<privatekey/>
<port/>
<description/>
<inventory_link>0</inventory_link>
<applications>
<application>
<name>Apache Stats</name>
</application>
</applications>
<valuemap/>
</item>
<item>
<name>Apache - Uptime</name>
<type>7</type>
<snmp_community>public</snmp_community>
<multiplier>0</multiplier>
<snmp_oid>interfaces.ifTable.ifEntry.ifInOctets.1</snmp_oid>
<key>apache[localhost,Uptime]</key>
<delay>60</delay>
<history>365</history>
<trends>9999</trends>
<status>0</status>
<value_type>3</value_type>
<allowed_hosts/>
<units>s</units>
<delta>0</delta>
<snmpv3_securityname/>
<snmpv3_securitylevel>0</snmpv3_securitylevel>
<snmpv3_authpassphrase/>
<snmpv3_privpassphrase/>
<formula>1</formula>
<delay_flex/>
<params/>
<ipmi_sensor/>
<data_type>0</data_type>
<authtype>0</authtype>
<username/>
<password/>
<publickey/>
<privatekey/>
<port/>
<description/>
<inventory_link>0</inventory_link>
<applications>
<application>
<name>Apache Stats</name>
</application>
</applications>
<valuemap/>
</item>
<item>
<name>Apache Workers - Closing Connection</name>
<type>7</type>
<snmp_community>public</snmp_community>
<multiplier>0</multiplier>
<snmp_oid>interfaces.ifTable.ifEntry.ifInOctets.1</snmp_oid>
<key>apache[localhost,Closingconnection]</key>
<delay>60</delay>
<history>365</history>
<trends>9999</trends>
<status>0</status>
<value_type>3</value_type>
<allowed_hosts/>
<units>Workers</units>
<delta>0</delta>
<snmpv3_securityname/>
<snmpv3_securitylevel>0</snmpv3_securitylevel>
<snmpv3_authpassphrase/>
<snmpv3_privpassphrase/>
<formula>1</formula>
<delay_flex/>
<params/>
<ipmi_sensor/>
<data_type>0</data_type>
<authtype>0</authtype>
<username/>
<password/>
<publickey/>
<privatekey/>
<port/>
<description/>
<inventory_link>0</inventory_link>
<applications>
<application>
<name>Apache Worker</name>
</application>
</applications>
<valuemap/>
</item>
<item>
<name>Apache Workers - DNS Lookup</name>
<type>7</type>
<snmp_community>public</snmp_community>
<multiplier>0</multiplier>
<snmp_oid>interfaces.ifTable.ifEntry.ifInOctets.1</snmp_oid>
<key>apache[localhost,DNSLookup]</key>
<delay>60</delay>
<history>365</history>
<trends>9999</trends>
<status>0</status>
<value_type>3</value_type>
<allowed_hosts/>
<units>Workers</units>
<delta>0</delta>
<snmpv3_securityname/>
<snmpv3_securitylevel>0</snmpv3_securitylevel>
<snmpv3_authpassphrase/>
<snmpv3_privpassphrase/>
<formula>1</formula>
<delay_flex/>
<params/>
<ipmi_sensor/>
<data_type>0</data_type>
<authtype>0</authtype>
<username/>
<password/>
<publickey/>
<privatekey/>
<port/>
<description/>
<inventory_link>0</inventory_link>
<applications>
<application>
<name>Apache Worker</name>
</application>
</applications>
<valuemap/>
</item>
<item>
<name>Apache Workers - Gracefully Finishing</name>
<type>7</type>
<snmp_community>public</snmp_community>
<multiplier>0</multiplier>
<snmp_oid>interfaces.ifTable.ifEntry.ifInOctets.1</snmp_oid>
<key>apache[localhost,Gracefullyfinishing]</key>
<delay>60</delay>
<history>365</history>
<trends>9999</trends>
<status>0</status>
<value_type>3</value_type>
<allowed_hosts/>
<units>Workers</units>
<delta>0</delta>
<snmpv3_securityname/>
<snmpv3_securitylevel>0</snmpv3_securitylevel>
<snmpv3_authpassphrase/>
<snmpv3_privpassphrase/>
<formula>1</formula>
<delay_flex/>
<params/>
<ipmi_sensor/>
<data_type>0</data_type>
<authtype>0</authtype>
<username/>
<password/>
<publickey/>
<privatekey/>
<port/>
<description/>
<inventory_link>0</inventory_link>
<applications>
<application>
<name>Apache Worker</name>
</application>
</applications>
<valuemap/>
</item>
<item>
<name>Apache Workers - Idle cleanup of worker</name>
<type>7</type>
<snmp_community>public</snmp_community>
<multiplier>0</multiplier>
<snmp_oid>interfaces.ifTable.ifEntry.ifInOctets.1</snmp_oid>
<key>apache[localhost,Idlecleanupofworker]</key>
<delay>60</delay>
<history>365</history>
<trends>9999</trends>
<status>0</status>
<value_type>3</value_type>
<allowed_hosts/>
<units>Workers</units>
<delta>0</delta>
<snmpv3_securityname/>
<snmpv3_securitylevel>0</snmpv3_securitylevel>
<snmpv3_authpassphrase/>
<snmpv3_privpassphrase/>
<formula>1</formula>
<delay_flex/>
<params/>
<ipmi_sensor/>
<data_type>0</data_type>
<authtype>0</authtype>
<username/>
<password/>
<publickey/>
<privatekey/>
<port/>
<description/>
<inventory_link>0</inventory_link>
<applications>
<application>
<name>Apache Worker</name>
</application>
</applications>
<valuemap/>
</item>
<item>
<name>Apache Workers - Keepalive (read)</name>
<type>7</type>
<snmp_community>public</snmp_community>
<multiplier>0</multiplier>
<snmp_oid>interfaces.ifTable.ifEntry.ifInOctets.1</snmp_oid>
<key>apache[localhost,Keepaliveread]</key>
<delay>60</delay>
<history>365</history>
<trends>9999</trends>
<status>0</status>
<value_type>3</value_type>
<allowed_hosts/>
<units>Workers</units>
<delta>0</delta>
<snmpv3_securityname/>
<snmpv3_securitylevel>0</snmpv3_securitylevel>
<snmpv3_authpassphrase/>
<snmpv3_privpassphrase/>
<formula>1</formula>
<delay_flex/>
<params/>
<ipmi_sensor/>
<data_type>0</data_type>
<authtype>0</authtype>
<username/>
<password/>
<publickey/>
<privatekey/>
<port/>
<description/>
<inventory_link>0</inventory_link>
<applications>
<application>
<name>Apache Worker</name>
</application>
</applications>
<valuemap/>
</item>
<item>
<name>Apache Workers - Logging</name>
<type>7</type>
<snmp_community>public</snmp_community>
<multiplier>0</multiplier>
<snmp_oid>interfaces.ifTable.ifEntry.ifInOctets.1</snmp_oid>
<key>apache[localhost,Logging]</key>
<delay>60</delay>
<history>365</history>
<trends>9999</trends>
<status>0</status>
<value_type>3</value_type>
<allowed_hosts/>
<units>Workers</units>
<delta>0</delta>
<snmpv3_securityname/>
<snmpv3_securitylevel>0</snmpv3_securitylevel>
<snmpv3_authpassphrase/>
<snmpv3_privpassphrase/>
<formula>1</formula>
<delay_flex/>
<params/>
<ipmi_sensor/>
<data_type>0</data_type>
<authtype>0</authtype>
<username/>
<password/>
<publickey/>
<privatekey/>
<port/>
<description/>
<inventory_link>0</inventory_link>
<applications>
<application>
<name>Apache Worker</name>
</application>
</applications>
<valuemap/>
</item>
<item>
<name>Apache Workers - Open slot with no current process</name>
<type>7</type>
<snmp_community>public</snmp_community>
<multiplier>0</multiplier>
<snmp_oid>interfaces.ifTable.ifEntry.ifInOctets.1</snmp_oid>
<key>apache[localhost,Openslotwithnocurrentprocess]</key>
<delay>60</delay>
<history>365</history>
<trends>9999</trends>
<status>0</status>
<value_type>3</value_type>
<allowed_hosts/>
<units>Workers</units>
<delta>0</delta>
<snmpv3_securityname/>
<snmpv3_securitylevel>0</snmpv3_securitylevel>
<snmpv3_authpassphrase/>
<snmpv3_privpassphrase/>
<formula>1</formula>
<delay_flex/>
<params/>
<ipmi_sensor/>
<data_type>0</data_type>
<authtype>0</authtype>
<username/>
<password/>
<publickey/>
<privatekey/>
<port/>
<description/>
<inventory_link>0</inventory_link>
<applications>
<application>
<name>Apache Worker</name>
</application>
</applications>
<valuemap/>
</item>
<item>
<name>Apache Workers - Reading Request</name>
<type>7</type>
<snmp_community>public</snmp_community>
<multiplier>0</multiplier>
<snmp_oid>interfaces.ifTable.ifEntry.ifInOctets.1</snmp_oid>
<key>apache[localhost,ReadingRequest]</key>
<delay>60</delay>
<history>365</history>
<trends>9999</trends>
<status>0</status>
<value_type>3</value_type>
<allowed_hosts/>
<units>Workers</units>
<delta>0</delta>
<snmpv3_securityname/>
<snmpv3_securitylevel>0</snmpv3_securitylevel>
<snmpv3_authpassphrase/>
<snmpv3_privpassphrase/>
<formula>1</formula>
<delay_flex/>
<params/>
<ipmi_sensor/>
<data_type>0</data_type>
<authtype>0</authtype>
<username/>
<password/>
<publickey/>
<privatekey/>
<port/>
<description/>
<inventory_link>0</inventory_link>
<applications>
<application>
<name>Apache Worker</name>
</application>
</applications>
<valuemap/>
</item>
<item>
<name>Apache Workers - Sending Reply</name>
<type>7</type>
<snmp_community>public</snmp_community>
<multiplier>0</multiplier>
<snmp_oid>interfaces.ifTable.ifEntry.ifInOctets.1</snmp_oid>
<key>apache[localhost,SendingReply]</key>
<delay>60</delay>
<history>365</history>
<trends>9999</trends>
<status>0</status>
<value_type>3</value_type>
<allowed_hosts/>
<units>Workers</units>
<delta>0</delta>
<snmpv3_securityname/>
<snmpv3_securitylevel>0</snmpv3_securitylevel>
<snmpv3_authpassphrase/>
<snmpv3_privpassphrase/>
<formula>1</formula>
<delay_flex/>
<params/>
<ipmi_sensor/>
<data_type>0</data_type>
<authtype>0</authtype>
<username/>
<password/>
<publickey/>
<privatekey/>
<port/>
<description/>
<inventory_link>0</inventory_link>
<applications>
<application>
<name>Apache Worker</name>
</application>
</applications>
<valuemap/>
</item>
<item>
<name>Apache Workers - Starting up</name>
<type>7</type>
<snmp_community>public</snmp_community>
<multiplier>0</multiplier>
<snmp_oid>interfaces.ifTable.ifEntry.ifInOctets.1</snmp_oid>
<key>apache[localhost,Startingup]</key>
<delay>60</delay>
<history>365</history>
<trends>9999</trends>
<status>0</status>
<value_type>3</value_type>
<allowed_hosts/>
<units>Workers</units>
<delta>0</delta>
<snmpv3_securityname/>
<snmpv3_securitylevel>0</snmpv3_securitylevel>
<snmpv3_authpassphrase/>
<snmpv3_privpassphrase/>
<formula>1</formula>
<delay_flex/>
<params/>
<ipmi_sensor/>
<data_type>0</data_type>
<authtype>0</authtype>
<username/>
<password/>
<publickey/>
<privatekey/>
<port/>
<description/>
<inventory_link>0</inventory_link>
<applications>
<application>
<name>Apache Worker</name>
</application>
</applications>
<valuemap/>
</item>
<item>
<name>Apache Workers - Waiting for Connection</name>
<type>7</type>
<snmp_community>public</snmp_community>
<multiplier>0</multiplier>
<snmp_oid>interfaces.ifTable.ifEntry.ifInOctets.1</snmp_oid>
<key>apache[localhost,WaitingforConnection]</key>
<delay>60</delay>
<history>365</history>
<trends>9999</trends>
<status>0</status>
<value_type>3</value_type>
<allowed_hosts/>
<units>s</units>
<delta>0</delta>
<snmpv3_securityname/>
<snmpv3_securitylevel>0</snmpv3_securitylevel>
<snmpv3_authpassphrase/>
<snmpv3_privpassphrase/>
<formula>1</formula>
<delay_flex/>
<params/>
<ipmi_sensor/>
<data_type>0</data_type>
<authtype>0</authtype>
<username/>
<password/>
<publickey/>
<privatekey/>
<port/>
<description/>
<inventory_link>0</inventory_link>
<applications>
<application>
<name>Apache Worker</name>
</application>
</applications>
<valuemap/>
</item>
</items>
<discovery_rules/>
<macros/>
<templates/>
<screens/>
</template>
</templates>
</zabbix_export>
#!/usr/bin/python
""" Fetch Apache stats via mod_status and send to Zabbix
By Paulson McIntyre
Patches by:
Zach Bailey <znbailey@gmail.com>
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
"""
# /etc/zabbix/scripts/ZabbixApacheUpdater.py
#
# to cron:
# * * * * * /etc/zabbix/scripts/ZabbixApacheUpdater.py -c client.com -z server.com > /dev/null 2>&1
import urllib
from optparse import OptionParser
import os
from tempfile import mkstemp
import StringIO
import csv
class ErrorSendingValues(RuntimeError):
""" An error occured while sending the values to the Zabbix
server using zabbix_sender.
"""
def fetchURL(url, user = None, passwd = None):
""" Return the data from a URL """
if user and passwd:
parts = url.split('://')
url = parts[0] + "://" + user + ":" + passwd + "@" + parts[1]
conn = urllib.urlopen(url)
try:
data = conn.read()
finally:
conn.close()
return data
def sendValues(filepath, zabbixserver = "localhost", zabbixport = 10051, senderloc = "zabbix_sender"):
r = os.system("%s --zabbix-server '%s' --port '%s' -i '%s' -vv" % (senderloc, zabbixserver, zabbixport, filepath))
if r != 0:
raise ErrorSendingValues, "An error occured sending the values to the server"
def clean(string, chars):
for i in chars:
string = string.replace(i, '')
return string
def parse(data):
""" Parse the CSV file into a dict of data
"""
mapping = {
"_":"Waiting for Connection",
"S":"Starting up",
"R":"Reading Request",
"W":"Sending Reply",
"K":"Keepalive (read)",
"D":"DNS Lookup",
"C":"Closing connection",
"L":"Logging",
"G":"Gracefully finishing",
"I":"Idle cleanup of worker",
".":"Open slot with no current process",
}
# Clean out certian chars
replace = '() '
csvobj = csv.reader(StringIO.StringIO(data), delimiter = ":", skipinitialspace = True)
ret = {}
for (key, val) in csvobj:
if key == 'Scoreboard':
sb = {
"Waiting for Connection":0,
"Starting up":0,
"Reading Request":0,
"Sending Reply":0,
"Keepalive (read)":0,
"DNS Lookup":0,
"Closing connection":0,
"Logging":0,
"Gracefully finishing":0,
"Idle cleanup of worker":0,
"Open slot with no current process":0,
}
for i in val:
sb[mapping[i]] += 1
ret[key] = sb
else:
ret[key] = val
ret2 = {}
for (key, val) in ret.items():
if key == "Scoreboard":
for (key, val) in val.items():
ret2[clean(key, replace)] = val
else:
ret2[clean(key, replace)] = val
return ret2
if __name__ == "__main__":
parser = OptionParser(
usage = "%prog [-z <Zabbix hostname or IP>] [-o <Apache hostname or IP>]",
version = "%prog $Revision: 173 $",
prog = "ApacheStatsForZabbix",
description = """This program gathers data from Apache's
built-in status page and sends it to
Zabbix. The data is sent via zabbix_sender.
Author: Paulson McIntyre (GpMidi)
License: GPLv2
""",
)
parser.add_option(
"-l",
"--url",
action = "store",
type = "string",
dest = "url",
default = None,
help = "Override the automatically generated URL with one of your own",
)
parser.add_option(
"-o",
"--host",
action = "store",
type = "string",
dest = "host",
default = "localhost",
help = "Host to connect to. [default: %default]",
)
parser.add_option(
"-p",
"--port",
action = "store",
type = "int",
dest = "port",
default = 80,
help = "Port to connect on. [default: %default]",
)
parser.add_option(
"-r",
"--proto",
action = "store",
type = "string",
dest = "proto",
default = "http",
help = "Protocol to connect on. Can be http or https. [default: %default]",
)
parser.add_option(
"-z",
"--zabbixserver",
action = "store",
type = "string",
dest = "zabbixserver",
default = "localhost",
)
parser.add_option(
"-u",
"--user",
action = "store",
type = "string",
dest = "user",
default = None,
help = "HTTP authentication user to use when connection. [default: None]",
)
parser.add_option(
"-a",
"--passwd",
action = "store",
type = "string",
dest = "passwd",
default = None,
help = "HTTP authentication password to use when connecting. [default: None]",
)
parser.add_option(
"-s",
"--sender",
action = "store",
type = "string",
dest = "senderloc",
default = "/usr/bin/zabbix_sender",
help = "Location to the zabbix_sender executable. [default: %default]",
)
parser.add_option(
"-q",
"--zabbixport",
action = "store",
type = "int",
dest = "zabbixport",
default = 10051,
help = "Zabbix port to connect to. [default: %default]",
)
parser.add_option(
"-c",
"--zabbixsource",
action = "store",
type = "string",
dest = "zabbixsource",
default = "localhost",
help = "Zabbix host to use when sending values. [default: %default]",
)
(opts, args) = parser.parse_args()
if opts.url and (opts.port != 80 or opts.proto != "http"):
parser.error("Can't specify -u with -p or -r")
if not opts.url:
opts.url = "%s://%s:%s/server-status?auto" % (opts.proto, opts.host, opts.port)
data = fetchURL(opts.url, user = opts.user, passwd = opts.passwd)
try:
(tempfiled, tempfilepath) = mkstemp()
tempfile = open(tempfilepath, 'wb')
except:
parser.error("Error creating temporary file")
try:
try:
data = parse(data = data)
except csv.Error:
parser.error("Error parsing returned data")
try:
for key, val in data.items():
tempfile.write("%s apache[%s,%s] %s\n" % (opts.zabbixsource, opts.host, key, val))
tempfile.close()
except "bogus":
parser.error("Error creating the file to send")
try:
sendValues(filepath = tempfilepath, zabbixserver = opts.zabbixserver, zabbixport = opts.zabbixport, senderloc = opts.senderloc)
except ErrorSendingValues:
parser.error("An error occurred while sending values to the Zabbix server")
finally:
try:
tempfile.close()
except:
pass
os.remove(tempfilepath)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment