Skip to content

Commit

Permalink
update deb package and plugins, fix xinetd package name
Browse files Browse the repository at this point in the history
  • Loading branch information
elnappo committed Jul 4, 2017
1 parent 3e5a82c commit 29f290e
Show file tree
Hide file tree
Showing 61 changed files with 3,751 additions and 728 deletions.
12 changes: 8 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,15 +1,18 @@
# ansible-role-check-mk-agent [![Build Status](https://travis-ci.org/elnappo/ansible-role-check-mk-agent.svg?branch=master)](https://travis-ci.org/elnappo/ansible-role-check-mk-agent)
Installs check mk agent. Run it with xinit or over ssh (default). Get more informations about check mk at [https://mathias-kettner.de/check_mk.html]()
Installs check mk\_agent. Run it with xinetd or over SSH (default). Get more informations about check\_mk at [https://mathias-kettner.de/check_mk.html]()

## Requirements
Only testet with Ubuntu and Debian, should run on more platforms.
Only testet with Ubuntu 14.04 and 16.04, should run on more platforms.

## Install
$ ansible-galaxy install elnappoo.check-mk-agent

## Role Variables
* `check_mk_agent_deb_package: check-mk-agent_1.2.6p16-1_all.deb` Path to deb package
* `check_mk_agent_deb_package: check-mk-agent_1.4.0p7-1_all.deb` Path to deb package
* `check_mk_agent_over_ssh: True`
* `check_mk_agent_plugins_requirements: []` Requirements for extra plugins
* `check_mk_agent_plugins: []` List of extra plugins to install
* `check_mk_agent_pubkey_file:` Path to ssh pubkey file
* `check_mk_agent_pubkey_file:` Path to SSH pubkey file

## Included check_mk extra plugins
* apache\_status
Expand Down Expand Up @@ -72,3 +75,4 @@ MIT
## Author Information
elnappo <elnappo@nerdpol.io>
2 changes: 1 addition & 1 deletion defaults/main.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
---
# defaults file for agent
check_mk_agent_deb_package: check-mk-agent_1.2.6p16-1_all.deb
check_mk_agent_deb_package: check-mk-agent_1.4.0p7-1_all.deb
check_mk_agent_over_ssh: True
check_mk_agent_plugins_requirements: []
check_mk_agent_plugins: []
Expand Down
Binary file removed files/check-mk-agent_1.2.6p16-1_all.deb
Binary file not shown.
Binary file added files/check-mk-agent_1.4.0p7-1_all.deb
Binary file not shown.
44 changes: 33 additions & 11 deletions files/plugins/apache_status
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
# in the hope that it will be useful, but WITHOUT ANY WARRANTY; with-
# out even the implied warranty of MERCHANTABILITY or FITNESS FOR A
# PARTICULAR PURPOSE. See the GNU General Public License for more de-
# ails. You should have received a copy of the GNU General Public
# tails. You should have received a copy of the GNU General Public
# License along with GNU Make; see the file COPYING. If not, write
# to the Free Software Foundation, Inc., 51 Franklin St, Fifth Floor,
# Boston, MA 02110-1301 USA.
Expand Down Expand Up @@ -63,9 +63,11 @@ 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
Expand All @@ -91,33 +93,38 @@ def try_detect_servers():
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'
address = '[::1]'
elif ':' in address:
address = '[%s]' % address

# 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'
else:
proto = 'http'

results.append((proto, address, port))

return results


if servers is None:
servers = try_detect_servers()


if not servers:
sys.exit(0)

print '<<<apache_status>>>'

sys.stdout.write('<<<apache_status>>>\n')
for server in servers:
if isinstance(server, tuple):
proto, address, port = server
Expand All @@ -128,17 +135,28 @@ for server in servers:
port = server['port']
page = server.get('page', 'server-status')

portspec = port and ":%d" % port or ""

try:
url = '%s://%s:%s/%s?auto' % (proto, address, port, page)
url = '%s://%s%s/%s?auto' % (proto, address, portspec, page)
# Try to fetch the status page for each server
try:
request = urllib2.Request(url, headers={"Accept" : "text/plain"})
fd = urllib2.urlopen(request)
except urllib2.URLError, e:
if 'SSL23_GET_SERVER_HELLO:unknown protocol' in str(e):
if '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)
url = 'http://%s%s/server-status?auto' % (address, portspec)
fd = urllib2.urlopen(url)
else:
raise
except Exception, e:
if 'doesn\'t match' in str(e):
# HACK: workaround if SSL port is found and localhost is using
# SSL connections but certificate does not match
portspec = ':80'
url = 'http://%s%s/server-status?auto' % (address, portspec)
fd = urllib2.urlopen(url)
else:
raise
Expand All @@ -147,11 +165,15 @@ for server in servers:
if not line.strip():
continue
if line.lstrip()[0] == '<':
# seems to be html output. Skip this server.
# Seems to be html output. Skip this server.
break
print address, port, line

if ':' in address:
sys.stdout.write("%s %s %s\n" % (address.lstrip('[').rstrip(']'), port, line))
else:
sys.stdout.write("%s %s %s\n" % (address, port, line))
except urllib2.HTTPError, e:
sys.stderr.write('HTTP-Error (%s:%d): %s %s\n' % (address, port, e.code, e))
sys.stderr.write('HTTP-Error (%s%s): %s %s\n' % (address, portspec, e.code, e))

except Exception, e:
sys.stderr.write('Exception (%s:%d): %s\n' % (address, port, e))
sys.stderr.write('Exception (%s%s): %s\n' % (address, portspec, e))
26 changes: 26 additions & 0 deletions files/plugins/asmcmd.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
#!/bin/sh
# +------------------------------------------------------------------+
# | ____ _ _ __ __ _ __ |
# | / ___| |__ ___ ___| | __ | \/ | |/ / |
# | | | | '_ \ / _ \/ __| |/ / | |\/| | ' / |
# | | |___| | | | __/ (__| < | | | | . \ |
# | \____|_| |_|\___|\___|_|\_\___|_| |_|_|\_\ |
# | |
# | Copyright Mathias Kettner 2014 mk@mathias-kettner.de |
# +------------------------------------------------------------------+
#
# This file is part of Check_MK.
# The official homepage is at http://mathias-kettner.de/check_mk.
#
# check_mk 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 in version 2. check_mk is distributed
# in the hope that it will be useful, but WITHOUT ANY WARRANTY; with-
# out even the implied warranty of MERCHANTABILITY or FITNESS FOR A
# PARTICULAR PURPOSE. See the GNU General Public License for more de-
# tails. You should have received a copy of the GNU General Public
# License along with GNU Make; see the file COPYING. If not, write
# to the Free Software Foundation, Inc., 51 Franklin St, Fifth Floor,
# Boston, MA 02110-1301 USA.

su - griduser -c "asmcmd $@"
2 changes: 1 addition & 1 deletion files/plugins/db2_mem
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
# in the hope that it will be useful, but WITHOUT ANY WARRANTY; with-
# out even the implied warranty of MERCHANTABILITY or FITNESS FOR A
# PARTICULAR PURPOSE. See the GNU General Public License for more de-
# ails. You should have received a copy of the GNU General Public
# tails. You should have received a copy of the GNU General Public
# License along with GNU Make; see the file COPYING. If not, write
# to the Free Software Foundation, Inc., 51 Franklin St, Fifth Floor,
# Boston, MA 02110-1301 USA.
Expand Down
2 changes: 1 addition & 1 deletion files/plugins/dnsclient
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
# in the hope that it will be useful, but WITHOUT ANY WARRANTY; with-
# out even the implied warranty of MERCHANTABILITY or FITNESS FOR A
# PARTICULAR PURPOSE. See the GNU General Public License for more de-
# ails. You should have received a copy of the GNU General Public
# tails. You should have received a copy of the GNU General Public
# License along with GNU Make; see the file COPYING. If not, write
# to the Free Software Foundation, Inc., 51 Franklin St, Fifth Floor,
# Boston, MA 02110-1301 USA.
Expand Down
3 changes: 2 additions & 1 deletion files/plugins/hpux_lunstats
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
#!/usr/bin/ksh
# Monitor status of LUNs on HP-UX
# +------------------------------------------------------------------+
# | ____ _ _ __ __ _ __ |
# | / ___| |__ ___ ___| | __ | \/ | |/ / |
Expand All @@ -18,7 +19,7 @@
# in the hope that it will be useful, but WITHOUT ANY WARRANTY; with-
# out even the implied warranty of MERCHANTABILITY or FITNESS FOR A
# PARTICULAR PURPOSE. See the GNU General Public License for more de-
# ails. You should have received a copy of the GNU General Public
# tails. You should have received a copy of the GNU General Public
# License along with GNU Make; see the file COPYING. If not, write
# to the Free Software Foundation, Inc., 51 Franklin St, Fifth Floor,
# Boston, MA 02110-1301 USA.
Expand Down
2 changes: 1 addition & 1 deletion files/plugins/hpux_statgrab
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
# in the hope that it will be useful, but WITHOUT ANY WARRANTY; with-
# out even the implied warranty of MERCHANTABILITY or FITNESS FOR A
# PARTICULAR PURPOSE. See the GNU General Public License for more de-
# ails. You should have received a copy of the GNU General Public
# tails. You should have received a copy of the GNU General Public
# License along with GNU Make; see the file COPYING. If not, write
# to the Free Software Foundation, Inc., 51 Franklin St, Fifth Floor,
# Boston, MA 02110-1301 USA.
Expand Down
85 changes: 85 additions & 0 deletions files/plugins/isc_dhcpd
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
#!/usr/bin/python
# Monitor leases if ISC-DHCPD

import os, sys, time, re, calendar

conf_file = None
for path in [ '/etc/dhcpd.conf', '/etc/dhcp/dhcpd.conf', '/usr/local/etc/dhcpd.conf' ]:
if os.path.exists(path):
conf_file = path
break

leases_file = None
for path in [
'/var/lib/dhcp/db/dhcpd.leases',
'/var/lib/dhcp/dhcpd.leases',
'/var/lib/dhcpd/dhcpd.leases', # CentOS
]:
if os.path.exists(path):
leases_file = path
break

# If no configuration and leases are found, we assume that
# no dhcpd is running.
if not conf_file or not leases_file:
sys.exit(0)

pidof_dhcpd = os.popen("pidof dhcpd").read().strip()
sys.stdout.write('<<<isc_dhcpd>>>\n[general]\nPID: %s\n' % pidof_dhcpd)

sys.stdout.write('[pools]\n')


def parse_config(filename):
for line in file(filename):
line = line.strip()
if line.startswith("include"):
included_file = re.search('include\s+"(.*)"', line).group(1)
parse_config(included_file)
elif line.startswith("range"):
sys.stdout.write(line[5:].strip("\t ;") + "\n")

parse_config(conf_file)


# lease 10.1.1.81 {
# starts 3 2015/09/09 11:42:20;
# ends 3 2015/09/09 19:42:20;
# tstp 3 2015/09/09 19:42:20;
# cltt 3 2015/09/09 11:42:20;
# binding state free;
# hardware ethernet a4:5e:60:de:1f:c3;
# uid "\001\244^`\336\037\303";
# set ddns-txt = "318c69bae8aeae6f8c723e96de933c7149";
# set ddns-fwd-name = "Sebastians-MBP.dhcp.mathias-kettner.de";
# }

sys.stdout.write('[leases]\n')
now = time.time()
ip_address = None
binding_state = None
seen_addresses = set()
for line in file(leases_file):
parts = line.strip().rstrip(";").split()
if not parts:
continue

if parts[0] == "lease":
ip_address = parts[1]
elif parts[0] == "ends":
if parts[1] != "never":
ends_date_string = parts[2] + " " + parts[3]
ends_date = calendar.timegm(time.strptime(ends_date_string, "%Y/%m/%d %H:%M:%S"))
if ends_date < now:
ip_address = None # skip this address, this lease is outdated

elif parts[0] == "binding" and parts[1] == "state":
binding_state = parts[2]

elif parts[0] == "}":
if ip_address and binding_state == "active" and ip_address not in seen_addresses:
sys.stdout.write("%s\n" % ip_address)
seen_addresses.add(ip_address)
ip_address = None
binding_state = None

2 changes: 1 addition & 1 deletion files/plugins/jar_signature
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
# in the hope that it will be useful, but WITHOUT ANY WARRANTY; with-
# out even the implied warranty of MERCHANTABILITY or FITNESS FOR A
# PARTICULAR PURPOSE. See the GNU General Public License for more de-
# ails. You should have received a copy of the GNU General Public
# tails. You should have received a copy of the GNU General Public
# License along with GNU Make; see the file COPYING. If not, write
# to the Free Software Foundation, Inc., 51 Franklin St, Fifth Floor,
# Boston, MA 02110-1301 USA.
Expand Down
2 changes: 1 addition & 1 deletion files/plugins/kaspersky_av
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
# in the hope that it will be useful, but WITHOUT ANY WARRANTY; with-
# out even the implied warranty of MERCHANTABILITY or FITNESS FOR A
# PARTICULAR PURPOSE. See the GNU General Public License for more de-
# ails. You should have received a copy of the GNU General Public
# tails. You should have received a copy of the GNU General Public
# License along with GNU Make; see the file COPYING. If not, write
# to the Free Software Foundation, Inc., 51 Franklin St, Fifth Floor,
# Boston, MA 02110-1301 USA.
Expand Down
16 changes: 12 additions & 4 deletions files/plugins/lnx_quota
Original file line number Diff line number Diff line change
Expand Up @@ -18,15 +18,23 @@
# in the hope that it will be useful, but WITHOUT ANY WARRANTY; with-
# out even the implied warranty of MERCHANTABILITY or FITNESS FOR A
# PARTICULAR PURPOSE. See the GNU General Public License for more de-
# ails. You should have received a copy of the GNU General Public
# tails. You should have received a copy of the GNU General Public
# License along with GNU Make; see the file COPYING. If not, write
# to the Free Software Foundation, Inc., 51 Franklin St, Fifth Floor,
# Boston, MA 02110-1301 USA.

if type repquota >/dev/null ; then
echo "<<<lnx_quota>>>"
for VOL in $(grep usrjquota /etc/fstab | cut -d' ' -f2); do
echo "[[[$VOL]]]"
repquota -up $VOL

# User Quota
for VOL in $(grep -E usr[j]?quota /etc/fstab | tr -s '\t' ' ' | cut -d' ' -f2); do
echo "[[[usr:$VOL]]]"
repquota -up $VOL | tail -n +6 | head -n -2
done

# Group Quota
for VOL in $(grep -E grp[j]?quota /etc/fstab | tr -s '\t' ' ' | cut -d' ' -f2); do
echo "[[[grp:$VOL]]]"
repquota -gp $VOL | tail -n +6 | head -n -2
done
fi
6 changes: 6 additions & 0 deletions files/plugins/lvm
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
#!/bin/bash
echo "<<<lvm_vgs>>>"
vgs --units b --nosuffix --noheadings --separator ' '

#echo "<<<lvm_pvs>>>"
#pvs --units b --nosuffix --noheadings --separator ' '
10 changes: 5 additions & 5 deletions files/plugins/mailman_lists
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
# in the hope that it will be useful, but WITHOUT ANY WARRANTY; with-
# out even the implied warranty of MERCHANTABILITY or FITNESS FOR A
# PARTICULAR PURPOSE. See the GNU General Public License for more de-
# ails. You should have received a copy of the GNU General Public
# tails. You should have received a copy of the GNU General Public
# License along with GNU Make; see the file COPYING. If not, write
# to the Free Software Foundation, Inc., 51 Franklin St, Fifth Floor,
# Boston, MA 02110-1301 USA.
Expand All @@ -35,10 +35,10 @@ sys.path.append("/usr/local/mailman")
# Set to True to filter out all "hidden" mailinglists
only_advertised = True

from Mailman import Utils, MailList
from Mailman import Utils, MailList # pylint: disable=import-error

# 1. list memberships
print '<<<mailman_lists>>>'
sys.stdout.write('<<<mailman_lists>>>\n')
total_members = set([])
for name in sorted(Utils.list_names()):
mlist = MailList.MailList(name, lock=0)
Expand All @@ -50,5 +50,5 @@ for name in sorted(Utils.list_names()):
members = rmembers + dmembers
total_members.update(members)

print '%s %d' % (name, len(members))
print 'TOTAL %d' % len(total_members)
sys.stdout.write('%s %d\n' % (name, len(members)))
sys.stdout.write('TOTAL %d\n' % len(total_members))
Loading

0 comments on commit 29f290e

Please sign in to comment.