···
2014-08-07 5:24 GMT+02:00 John Zimmerman <john.zimm@gmail.com>:
I'm having trouble getting the apache_status check to show up in my
inventory.
I have the plugin copied to the apache server with the config file. I can
run it locally on the apache server and get the expected output...
$ /usr/share/check-mk-agent/plugins/apache_status
<<<apache_status>>>
localhost 90 Total Accesses: 1102337
localhost 90 Total kBytes: 14460075
localhost 90 CPULoad: .0463671
localhost 90 Uptime: 330040
localhost 90 ReqPerSec: 3.34001
localhost 90 BytesPerSec: 44864.6
localhost 90 BytesPerReq: 13432.5
localhost 90 BusyWorkers: 2
localhost 90 IdleWorkers: 11
localhost 90 Scoreboard:
__W______W.._..._._.............................................................................................................................................................................................................................................
But when I telnet to the agent port or run an inventory against the host I
get nothing....
$ telnet localhost 6556
....
<<<job>>>
<<<local>>>
<<<apache_status>>>
<<<logwatch>>>
[[[/var/log/messages]]]
....
Anyone have ideas about what I am missing here?
_______________________________________________
checkmk-en mailing list
checkmk-en@lists.mathias-kettner.de
http://lists.mathias-kettner.de/mailman/listinfo/checkmk-en
#
# Fetches the server-status page from detected or configured apache
# processes to gather status information about this apache process.
#
# To make this agent plugin work you have to load the status_module
# into your apache process. It is also needed to enable the "server-status"
# handler below the URL "/server-status".
#
# By default this plugin tries to detect all locally running apache processes
# and to monitor them. If this is not good for your environment you might
# create an apache_status.cfg file in MK_CONFDIR and populate the servers
# list to prevent executing the detection mechanism.
#
# It is also possible to override or extend the ssl_ports variable to make the
# check contact other ports than 443 with HTTPS requests.
import os, sys, urllib2, re
config_dir = os.getenv("MK_CONFDIR", "/etc/check_mk")
config_file = config_dir + "/apache_status.conf"
if not os.path.exists(config_file):
config_file = config_dir + "/apache_status.cfg"
# None or list of (proto, ipaddress, port) tuples.
# proto is 'http' or 'https'
servers = None
ssl_ports = [ 443, ]
if os.path.exists(config_file):
execfile(config_file)
def try_detect_servers():
pids =
results =
for line in os.popen('netstat -tlnp 2>/dev/null').readlines():
parts = line.split()
# Skip lines with wrong format
if len(parts) < 7 or '/' not in parts[6]:
continue
pid, proc = parts[6].split('/', 1)
to_replace = re.compile('^.*/')
proc = to_replace.sub('', proc)
procs = [ 'apache2', 'httpd', 'httpd2-prefork',
'httpd2-worker', 'httpd.worker' ]
# the pid/proc field length is limited to 19 chars. Thus in case of
# long PIDs, the process names are stripped of by that length.
# Workaround this problem here
procs = [ p[:19 - len(pid) - 1] for p in procs ]
# Skip unwanted processes
if proc not in procs:
continue
# Add only the first found port of a single server process
if pid in pids:
continue
pids.append(pid)
proto = 'http'
address, port = parts[3].rsplit(':', 1)
port = int(port)
# Use localhost when listening globally
if address == '0.0.0.0':
address = '127.0.0.1'
elif address == '::':
address = '::1'
# Switch protocol if port is SSL port. In case you use SSL on another
# port you would have to change/extend the ssl_port list
if port in ssl_ports:
proto = 'https'
results.append((proto, address, port))
return results
if servers is None:
servers = try_detect_servers()
if not servers:
sys.exit(0)
print '<<<apache_status>>>'
for server in servers:
if isinstance(server, tuple):
proto, address, port = server
page = 'server-status'
else:
proto = server['protocol']
address = server['address']
port = server['port']
page = server.get('page', 'server-status')
try:
url = '%s://%s:%s/%s?auto' % (proto, address, port, page)
# Try to fetch the status page for each server
try:
fd = urllib2.urlopen(url)
except urllib2.URLError, e:
if 'SSL23_GET_SERVER_HELLO:unknown protocol' in str(e):
# HACK: workaround misconfigurations where port 443 is used for
# serving non ssl secured http
url = 'http://%s:%s/server-status?auto' % (address, port)
fd = urllib2.urlopen(url)
else:
raise
for line in fd.read().split('\n'):
if not line.strip():
continue
if line.lstrip()[0] == '<':
# seems to be html output. Skip this server.
break
print address, port, line
except urllib2.HTTPError, e:
sys.stderr.write('HTTP-Error (%s:%d): %s %s\n' % (address,
port, e.code, e))
except Exception, e:
sys.stderr.write('Exception (%s:%d): %s\n' % (address, port, e))
And:
You may create file apache_status.cfg in /etc/check_mk/ , with the
permission 400 with the content:
servers = [
{
'protocol' : 'http',
'address' : 'localhost',
'port' : 80 ,
},
{
'protocol' : 'https',
'address' : 'localhost',
'port' : 443 ,
},
]
And then discovery services from system monitoring...With web gui
check_mk or check_mk -II host
Regards