Skip to content

Commit

Permalink
refactoring
Browse files Browse the repository at this point in the history
- added GPL disclaimers
- migrated scripts to python3
- reformatting of sourcecode
- added discovery for real disks
- added simple smart disk monitoring
- migrated config of device discovery to json config
  • Loading branch information
Marc Schoechlin committed Oct 3, 2017
1 parent e9cc2a2 commit 88909dc
Show file tree
Hide file tree
Showing 15 changed files with 557 additions and 358 deletions.
15 changes: 15 additions & 0 deletions extension-files/tools/zabbix_check_apache
Original file line number Diff line number Diff line change
@@ -1,4 +1,19 @@
#!/bin/bash
#
# 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 2 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, write to the Free Software Foundation, Inc.,
# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.


export PATH="/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin:/root/bin:/usr/bin:/bin:$PATH"

Expand Down
14 changes: 14 additions & 0 deletions extension-files/tools/zabbix_check_apache-mod-jk
Original file line number Diff line number Diff line change
@@ -1,4 +1,18 @@
#!/bin/bash
#
# 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 2 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, write to the Free Software Foundation, Inc.,
# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.

export PATH="/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin:/root/bin:/usr/bin:/bin:$PATH"

Expand Down
15 changes: 15 additions & 0 deletions extension-files/tools/zabbix_check_apache-mod-status
Original file line number Diff line number Diff line change
@@ -1,4 +1,19 @@
#!/bin/bash
#
# 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 2 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, write to the Free Software Foundation, Inc.,
# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.


WHAT="$1"
PORT="${2:-80}"
Expand Down
23 changes: 20 additions & 3 deletions extension-files/tools/zabbix_check_dmesg
Original file line number Diff line number Diff line change
@@ -1,13 +1,29 @@
#!/usr/bin/env python3
#
# 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 2 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, write to the Free Software Foundation, Inc.,
# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.


import os
import re
import sys

try:
import cPickle as pickle
import cPickle as pickle
except ImportError:
import pickle
import pickle


def get_status_data(statusfile):
data = {}
Expand All @@ -19,6 +35,7 @@ def get_status_data(statusfile):
sys.stderr.write("ERROR: unable to read statusfile %s" % statusfile)
return data


######################################################################################################
# MAIN

Expand Down Expand Up @@ -77,4 +94,4 @@ if lines <= 0:
matched.append("parsing failed")

sys.stdout.write("%s: %s" % (status, ", ".join(matched)))
pickle.dump(status_data , open(status_file, "wb"))
pickle.dump(status_data, open(status_file, "wb"))
68 changes: 36 additions & 32 deletions extension-files/tools/zabbix_check_elasticsearch
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#!/usr/bin/env python
#!/usr/bin/env python3

# Created by Aaron Mildenstein on 19 SEP 2012
# Switchted from pyes to Elasticsearch for better Health Monitoring by Marcel Alburg on 17 JUN 2014
Expand All @@ -9,15 +9,21 @@ import sys
import json
import socket


# Define the fail message
def zbx_fail():
print "ZBX_NOTSUPPORTED"
print
"ZBX_NOTSUPPORTED"
sys.exit(2)

searchkeys = ['query_total', 'fetch_time_in_millis', 'fetch_total', 'fetch_time', 'query_current', 'fetch_current', 'query_time_in_millis']
getkeys = ['missing_total', 'exists_total', 'current', 'time_in_millis', 'missing_time_in_millis', 'exists_time_in_millis', 'total']


searchkeys = ['query_total', 'fetch_time_in_millis', 'fetch_total', 'fetch_time', 'query_current', 'fetch_current',
'query_time_in_millis']
getkeys = ['missing_total', 'exists_total', 'current', 'time_in_millis', 'missing_time_in_millis',
'exists_time_in_millis', 'total']
docskeys = ['count', 'deleted']
indexingkeys = ['delete_time_in_millis', 'index_total', 'index_current', 'delete_total', 'index_time_in_millis', 'delete_current']
indexingkeys = ['delete_time_in_millis', 'index_total', 'index_current', 'delete_total', 'index_time_in_millis',
'delete_current']
storekeys = ['size_in_bytes', 'throttle_time_in_millis']
cachekeys = ['filter_size_in_bytes', 'field_size_in_bytes', 'field_evictions']
clusterkeys = searchkeys + getkeys + docskeys + indexingkeys + storekeys
Expand All @@ -34,9 +40,8 @@ if len(sys.argv) < 3:

# Try to establish a connection to elasticsearch
try:
conn = Elasticsearch(socket.gethostname()+':9200', sniff_on_start=False)
except Exception, e:

conn = Elasticsearch(socket.gethostname() + ':9200', sniff_on_start=False)
except:
zbx_fail()

if sys.argv[1] == 'cluster':
Expand All @@ -45,22 +50,22 @@ if sys.argv[1] == 'cluster':
subtotal = 0
for nodename in nodestats['nodes']:
try:
if sys.argv[2] in indexingkeys:
indexstats = nodestats['nodes'][nodename]['indices']['indexing']
elif sys.argv[2] in storekeys:
indexstats = nodestats['nodes'][nodename]['indices']['store']
elif sys.argv[2] in getkeys:
indexstats = nodestats['nodes'][nodename]['indices']['get']
elif sys.argv[2] in docskeys:
indexstats = nodestats['nodes'][nodename]['indices']['docs']
elif sys.argv[2] in searchkeys:
indexstats = nodestats['nodes'][nodename]['indices']['search']
except Exception, e:
if sys.argv[2] in indexingkeys:
indexstats = nodestats['nodes'][nodename]['indices']['indexing']
elif sys.argv[2] in storekeys:
indexstats = nodestats['nodes'][nodename]['indices']['store']
elif sys.argv[2] in getkeys:
indexstats = nodestats['nodes'][nodename]['indices']['get']
elif sys.argv[2] in docskeys:
indexstats = nodestats['nodes'][nodename]['indices']['docs']
elif sys.argv[2] in searchkeys:
indexstats = nodestats['nodes'][nodename]['indices']['search']
except:
pass
try:
if sys.argv[2] in indexstats:
subtotal += indexstats[sys.argv[2]]
except Exception, e:
if sys.argv[2] in indexstats:
subtotal += indexstats[sys.argv[2]]
except:
pass
returnval = subtotal

Expand All @@ -69,12 +74,12 @@ if sys.argv[1] == 'cluster':
# Try to pull the managers object data
try:
escluster = conn.cluster
except Exception, e:
except:
zbx_fail()
# Try to get a value to match the key provided
try:
returnval = escluster.health()[sys.argv[2]]
except Exception, e:
except:
zbx_fail()
# If the key is "status" then we need to map that to an integer
if sys.argv[2] == 'status':
Expand All @@ -93,10 +98,10 @@ elif sys.argv[1] == 'service':
try:
conn.cluster.stats()
returnval = 1
except Exception, e:
except:
returnval = 0

else: # Not clusterwide, check the next arg
else: # Not clusterwide, check the next arg
nodestats = conn.nodes.stats()
for nodename in nodestats['nodes']:
if sys.argv[1] in nodestats['nodes'][nodename]['name']:
Expand All @@ -114,16 +119,15 @@ else: # Not clusterwide, check the next arg
stats = nodestats['nodes'][nodename]['indices']['cache']
try:
returnval = stats[sys.argv[2]]
except Exception, e:
except:
pass


# If we somehow did not get a value here, that's a problem. Send back the standard
# If we somehow did not get a value here, that's a problem. Send back the standard
# ZBX_NOTSUPPORTED
if returnval is None:
zbx_fail()
else:
print returnval
print
returnval

# End

113 changes: 47 additions & 66 deletions extension-files/tools/zabbix_check_multipath
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#!/usr/bin/env python
#!/usr/bin/env python3

# -*- coding: iso8859-1 -*-
#
Expand All @@ -24,91 +24,72 @@
import os.path
import sys
import re
import subprocess as subp
import subprocess

os.environ['LANG']="C"
os.environ['LANG'] = "C"

__author__ = "Marc Schoechlin <ms@256bit.org>"
__version__ = "$Revision$"


# path to smartctl
_multipathPath = r"/sbin/multipath"


def log(line):
print >>sys.stderr, "%s: %s" % (sys.argv[0],line)
sys.stderr.write("%s: %s\n" % (sys.argv[0], line))

#########################################################################
# check if multipathing is enabled

try:
proc = subp.Popen(["/sbin/lsmod"],stdout=subp.PIPE, stdin=subp.PIPE)
line = proc.stdout.readline()
except:
print "ERROR: lsmod"
log("UNKNOWN: lsmod call exits unexpectedly (%s)" % line)
sys.exit(1)

multipath_system = 0

while True:
line = proc.stdout.readline()
if (line == '' and proc.poll() != None):
break
match = re.match(r"^dm_multipath", line)
if match:
multipath_system = 1
break

if multipath_system == 0:
log("STATUS OK : No multipathing here")
print "OK: n/a"
sys.exit(0)
cmd = "lsmod"
process = subprocess.Popen(cmd, stdout=subprocess.PIPE, stderr=subprocess.PIPE, shell=True)
out, err = process.communicate()

multipath_system = False
for line in out.decode('utf8').splitlines():
match = re.match(r"^dm_multipath", line)
if match:
multipath_system = 1
break

if not multipath_system:
log("STATUS OK : No multipathing here")
print("OK: No multipathing here")
sys.exit(0)

#########################################################################
# check multipath setup
if not os.path.isfile(_multipathPath):
log("STATUS CRITICAL: multipath enabled, but multipath tool '%s' is not available" % _multipathPath)
sys.exit(1)

try:
proc = subp.Popen([_multipathPath,"-ll"],stdout=subp.PIPE)
line = proc.stdout.readline()
except:
log("UNKNOWN: multipath call exits unexpectedly (%s)" % line)
sys.exit(1)

paths = 0
broken_paths = 0
luns = 0
output = ""
while True:
line = proc.stdout.readline()
if (line == '' and proc.poll() != None):
break
output += sys.argv[0]+" "+line
match = re.match(r"^.+\s.*([a-f0-9]{33})",line)
if match:
ghosts = 0
lun = match.group(1)
luns += 1
continue
match = re.match(r"^.*(\d:\d:\d:\d).*$",line)
# A path
if not match:
continue
paths += 1

match = re.match(r"^.*\d:\d:\d:\d.*(faulty|failed).*$",line)
if match:
broken_paths += 1

cmd = "multipath -ll"
process = subprocess.Popen(cmd, stdout=subprocess.PIPE, stderr=subprocess.PIPE, shell=True)
out, err = process.communicate()

multipath_system = False
for line in out.decode('utf8').splitlines():

output += sys.argv[0] + " " + line
match = re.match(r"^.+\s.*([a-f0-9]{33})", line)
if match:
ghosts = 0
lun = match.group(1)
luns += 1
continue
match = re.match(r"^.*(\d:\d:\d:\d).*$", line)
# A path
if not match:
continue
paths += 1

match = re.match(r"^.*\d:\d:\d:\d.*(faulty|failed).*$", line)
if match:
broken_paths += 1

if (broken_paths > 0):
print "ERROR: L:%i,P:%i,B%i" %(luns,paths,broken_paths)
log(output)
print("ERROR: L:%i,P:%i,B%i" % (luns, paths, broken_paths))
log(output)
else:
print "OK: L:%i,P:%i,B%i" %(luns,paths,broken_paths)
log("OK: LUNS:%i, PATHS:%i, BROKEN PATHS %i" %(luns,paths,broken_paths))
print("OK: L:%i,P:%i,B%i" % (luns, paths, broken_paths))
log("OK: LUNS:%i, PATHS:%i, BROKEN PATHS %i" % (luns, paths, broken_paths))

# vim: ai et ts=2 shiftwidth=2 expandtab tabstop=3 tw=120
14 changes: 14 additions & 0 deletions extension-files/tools/zabbix_check_nginx-status
Original file line number Diff line number Diff line change
@@ -1,4 +1,18 @@
#!/bin/bash
#
# 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 2 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, write to the Free Software Foundation, Inc.,
# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.

WHAT="$1"
PORT="${2:-80}"
Expand Down
Loading

0 comments on commit 88909dc

Please sign in to comment.