Module: check_mk
Branch: master
Commit: fd283e35e8fba04b4c48b036c6ec082d16bd7c97
URL: http://git.mathias-kettner.de/git/?p=check_mk.git;a=commit;h=fd283e35e8fba0…
Author: Lars Michelsen <lm(a)mathias-kettner.de>
Date: Wed Nov 10 22:41:56 2010 +0100
check validation: Fixed typo
---
doc/helpers/validate_checks | 22 +++++++++++++---------
1 files changed, 13 insertions(+), 9 deletions(-)
diff --git a/doc/helpers/validate_checks b/doc/helpers/validate_checks
index 91c5577..d6cd425 100755
--- a/doc/helpers/validate_checks
+++ b/doc/helpers/validate_checks
@@ -93,15 +93,15 @@ def grep_manpage(check, match, section = None):
if section is None:
return not re.search(match, manpage) is None
else:
- started = False
- for line in manpage.split("\n"):
+ sec_started = False
+ for line in [ l.strip() for l in manpage.split("\n") ]:
if line == '[%s]' % section:
# Block starts with this line
- started = True
- elif started and line == '' or line.startswith('['):
+ sec_started = True
+ elif sec_started == True and (line == '' or line.startswith('[')):
# Reached nex section. Didn't find a match ... so return false
return False
- elif started:
+ elif sec_started == True:
if not re.search(match, line) is None:
return True
return False
@@ -166,10 +166,14 @@ def verify_global_vars(check):
if not var.islower():
invalid = True
- # Filter out known config vars
- # And check for correct prefix
- if not invalid and not grep_manpage(check, "^%s" % var, 'configuration') \
- and not var.startswith('%s_' % check_file):
+ # Documented configuration vars can be skipped
+ if not invalid and grep_manpage(check, "^%s" % var, 'configuration'):
+ continue
+ elif check == 'aironet_clients':
+ print 'found'
+
+ # Check unknown vars for correct prefix
+ if not var.startswith('%s_' % check_file):
invalid = True
if invalid:
Module: check_mk
Branch: master
Commit: 27bc10604a67dd056d8f455543a18b73c40d59f3
URL: http://git.mathias-kettner.de/git/?p=check_mk.git;a=commit;h=27bc10604a67dd…
Author: Lars Michelsen <lm(a)mathias-kettner.de>
Date: Wed Nov 10 22:12:34 2010 +0100
check validation: Added comments, added verbose mode to print out more details e.g. about wrong global vars per check
---
doc/helpers/validate_checks | 103 +++++++++++++++++++++++++++++++------------
1 files changed, 75 insertions(+), 28 deletions(-)
diff --git a/doc/helpers/validate_checks b/doc/helpers/validate_checks
index d273228..a0650c0 100755
--- a/doc/helpers/validate_checks
+++ b/doc/helpers/validate_checks
@@ -7,7 +7,7 @@
# - Zu viele?
# - Check Namen in der Variable?
-import os, sys, re
+import os, sys, re, getopt
import reindent
on_tty = sys.stdout.isatty()
@@ -80,6 +80,36 @@ def is_snmp_check(check):
def all_nonfunction_vars():
return set([ name for name,value in globals().items() if name[0] != '_' and type(value) != type(lambda:0) ])
+def get_manpage(check):
+ if not check in manpage:
+ try:
+ manpage[check] = open('checkman/%s' % check.split('.')[0]).read()
+ except IOError, e:
+ manpage[check] = ""
+ return manpage[check]
+
+def grep_manpage(check, match, section = None):
+ manpage = get_manpage(check)
+ if section is None:
+ return not re.search(match, manpage) is None
+ else:
+ started = False
+ for line in manpage.split("\n"):
+ if line == '[%s]' % section:
+ # Block starts with this line
+ started = True
+ elif started and line == '' or line.startswith('['):
+ # Reached nex section. Didn't find a match ... so return false
+ return False
+ elif started:
+ if not re.search(match, line) is None:
+ return True
+ return False
+
+def usage():
+ print "No real help available... The only option is -v|--verbose."
+ sys.exit(0)
+
ignored_variables = []
# Load all checks and record global var definitions
@@ -112,35 +142,13 @@ WEIGHT = { 'manpage': 2, 'global_vars': 2, 'reindent': 2 }
manpage = {}
-#
+# #############################################################################
# Check definitions
-#
+# #############################################################################
-def get_manpage(check):
- if not check in manpage:
- try:
- manpage[check] = open('checkman/%s' % check.split('.')[0]).read()
- except IOError, e:
- manpage[check] = ""
- return manpage[check]
-
-def grep_manpage(check, match, section = None):
- manpage = get_manpage(check)
- if section is None:
- return not re.search(match, manpage) is None
- else:
- started = False
- for line in manpage.split("\n"):
- if line == '[%s]' % section:
- # Block starts with this line
- started = True
- elif started and line == '' or line.startswith('['):
- # Reached nex section. Didn't find a match ... so return false
- return False
- elif started:
- if not re.search(match, line) is None:
- return True
- return False
+# Verify global vars:
+# - Are the global configuration vars mentioned in the manpage
+# - Are the other (internal) helper vars namend correctly
def is_valid_global_vars(check):
return True
@@ -172,6 +180,9 @@ def verify_global_vars(check):
return check_file in invalid_global_vars
+# Reindent code:
+# - Is there some code to be reindented?
+
def is_valid_reindent(check):
return True
@@ -181,30 +192,57 @@ def verify_reindent(check):
f.close()
return not r.run()
+# Manpage:
+# - Does the check have a manpage?
+
def is_valid_manpage(check):
return True
def verify_manpage(check):
return os.path.exists('checkman/%s' % check)
+# SNMP scan function:
+# - Does the snmp check have a scan function?
+
def is_valid_snmp_scan(check):
return is_snmp_check(check)
def verify_snmp_scan(check):
return check in snmp_scan_functions
+# PNP-Template:
+# Does the chekc which produces perfdata have a pnp template?
+
def is_valid_pnp_tmpl(check):
return check_has_perfdata(check)
def verify_pnp_tmpl(check):
return os.path.exists('pnp-templates/check_mk-%s.php' % check)
+# PNP-Template:
+# Does the chekc which produces perfdata have a rra config?
+
def is_valid_pnp_rra(check):
return check_has_perfdata(check)
def verify_pnp_rra(check):
return os.path.exists('pnp-rraconf/check_mk-%s.rra.cfg' % check)
+# #############################################################################
+# MAIN
+# #############################################################################
+
+_verbose = 0
+try:
+ opts, args = getopt.getopt(sys.argv[1:], "vh",
+ ["verbose", "help"])
+except getopt.error, msg:
+ usage(msg)
+for o, a in opts:
+ if o in ('-v', '--verbose'):
+ _verbose += 1
+ elif o in ('-h', '--help'):
+ usage()
# 1) Perform checks
#
@@ -262,3 +300,12 @@ for check, (score, check_results) in results:
sys.stdout.write('%s%-8s%s' % (color, score, tty_normal))
sys.stdout.write("\n")
+
+if _verbose > 0:
+ sys.stdout.write("\n")
+ sys.stdout.write("===========================================================================\n")
+ sys.stdout.write("Invalid global vars by check:\n")
+ sys.stdout.write("===========================================================================\n")
+ for check, vars in invalid_global_vars.iteritems():
+ for var in vars:
+ sys.stdout.write("%-25s: %s\n" % (check, var))
Module: check_mk
Branch: master
Commit: a590335da6ccdca345acddd7f1a373f22d77b08c
URL: http://git.mathias-kettner.de/git/?p=check_mk.git;a=commit;h=a590335da6ccdc…
Author: Lars Michelsen <lm(a)mathias-kettner.de>
Date: Wed Nov 10 22:21:14 2010 +0100
Sort invalid global vars by checkname
---
doc/helpers/validate_checks | 6 +++---
1 files changed, 3 insertions(+), 3 deletions(-)
diff --git a/doc/helpers/validate_checks b/doc/helpers/validate_checks
index a0650c0..91c5577 100755
--- a/doc/helpers/validate_checks
+++ b/doc/helpers/validate_checks
@@ -7,7 +7,7 @@
# - Zu viele?
# - Check Namen in der Variable?
-import os, sys, re, getopt
+import os, sys, re, getopt, operator
import reindent
on_tty = sys.stdout.isatty()
@@ -264,7 +264,6 @@ for check in get_all_checks():
#
# 2) Sort by score
#
-import operator
results = sorted(results.iteritems(), key=operator.itemgetter(1))
#
@@ -306,6 +305,7 @@ if _verbose > 0:
sys.stdout.write("===========================================================================\n")
sys.stdout.write("Invalid global vars by check:\n")
sys.stdout.write("===========================================================================\n")
- for check, vars in invalid_global_vars.iteritems():
+ # sort checks by name
+ for check, vars in sorted(invalid_global_vars.iteritems(), key=operator.itemgetter(0)):
for var in vars:
sys.stdout.write("%-25s: %s\n" % (check, var))
Module: check_mk
Branch: master
Commit: 9589fd9e64adf4441f8a1d1f1c6326a9917766ba
URL: http://git.mathias-kettner.de/git/?p=check_mk.git;a=commit;h=9589fd9e64adf4…
Author: Lars Michelsen <lm(a)mathias-kettner.de>
Date: Wed Nov 10 21:59:08 2010 +0100
check validation: Added global vars check
---
doc/helpers/validate_checks | 89 ++++++++++++++++++++++++++++++++++++++++--
1 files changed, 84 insertions(+), 5 deletions(-)
diff --git a/doc/helpers/validate_checks b/doc/helpers/validate_checks
index 1108402..d273228 100755
--- a/doc/helpers/validate_checks
+++ b/doc/helpers/validate_checks
@@ -1,14 +1,13 @@
#!/usr/bin/python
# Ideen:
-# - Reindent
# - Header
# - Copyright drin?
# - Globale Variablen
# - Zu viele?
# - Check Namen in der Variable?
-import os, sys
+import os, sys, re
import reindent
on_tty = sys.stdout.isatty()
@@ -78,21 +77,101 @@ def get_all_checks():
def is_snmp_check(check):
return check in snmp_info or check in snmp_info_single
-# Load all checks
+def all_nonfunction_vars():
+ return set([ name for name,value in globals().items() if name[0] != '_' and type(value) != type(lambda:0) ])
+
+ignored_variables = []
+
+# Load all checks and record global var definitions
+# Also read the man pages
+global_vars = {}
+invalid_global_vars = {}
for check in get_checks():
+ vars_before_check = all_nonfunction_vars()
execfile('checks/%s' % check)
+ vars_after_check = all_nonfunction_vars()
+
+ global_vars[check] = []
+ for name in vars_after_check:
+ if name not in ignored_variables and name not in vars_before_check:
+ global_vars[check] += [ name ]
SCORE_START = 10
C_OK = 1
C_FAILED = 2
C_INVALID = 3
-TESTS = { 'manpage': C_OK, 'snmp_scan': C_OK, 'pnp_tmpl': C_OK, 'pnp_rra': C_OK, 'snmp_scan': C_OK, 'reindent': C_OK }
-WEIGHT = { 'manpage': 2 }
+TESTS = { 'manpage': C_OK,
+ 'snmp_scan': C_OK,
+ 'pnp_tmpl': C_OK,
+ 'pnp_rra': C_OK,
+ 'snmp_scan': C_OK,
+ 'reindent': C_OK,
+ 'global_vars': C_OK,
+}
+WEIGHT = { 'manpage': 2, 'global_vars': 2, 'reindent': 2 }
+
+manpage = {}
#
# Check definitions
#
+def get_manpage(check):
+ if not check in manpage:
+ try:
+ manpage[check] = open('checkman/%s' % check.split('.')[0]).read()
+ except IOError, e:
+ manpage[check] = ""
+ return manpage[check]
+
+def grep_manpage(check, match, section = None):
+ manpage = get_manpage(check)
+ if section is None:
+ return not re.search(match, manpage) is None
+ else:
+ started = False
+ for line in manpage.split("\n"):
+ if line == '[%s]' % section:
+ # Block starts with this line
+ started = True
+ elif started and line == '' or line.startswith('['):
+ # Reached nex section. Didn't find a match ... so return false
+ return False
+ elif started:
+ if not re.search(match, line) is None:
+ return True
+ return False
+
+def is_valid_global_vars(check):
+ return True
+
+def verify_global_vars(check):
+ check_file = check.split('.')[0]
+
+ # No global vars registered by this check
+ if not check_file in global_vars:
+ return True
+
+ # Loop all global vars of this check and verify them
+ for var in global_vars[check_file]:
+ invalid = False
+ if not var.islower():
+ invalid = True
+
+ # Filter out known config vars
+ # And check for correct prefix
+ if not invalid and not grep_manpage(check, "^%s" % var, 'configuration') \
+ and not var.startswith('%s_' % check_file):
+ invalid = True
+
+ if invalid:
+ if not check_file in invalid_global_vars:
+ invalid_global_vars[check_file] = [ var ]
+ else:
+ invalid_global_vars[check_file] += [ var ]
+
+ return check_file in invalid_global_vars
+
def is_valid_reindent(check):
return True
Module: check_mk
Branch: master
Commit: f4b84dbf2eeec40aa0538149b929658e3569dcb4
URL: http://git.mathias-kettner.de/git/?p=check_mk.git;a=commit;h=f4b84dbf2eeec4…
Author: Lars Michelsen <lm(a)mathias-kettner.de>
Date: Mon Nov 8 11:18:29 2010 +0100
heartbeat_rscstatus: Allowing a list as expected state to expect multiple OK states
---
ChangeLog | 1 +
checkman/heartbeat_rscstatus | 5 +++++
checks/heartbeat_rscstatus | 9 +++------
3 files changed, 9 insertions(+), 6 deletions(-)
diff --git a/ChangeLog b/ChangeLog
index 815e857..bcb06bf 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -59,6 +59,7 @@
* heartbeat_nodes: fix Linux agent for hostname with upper case letters (thanks to
Thorsten Robers)
* heartbeat_rscstatus: Catching empty output from agent correctly
+ * heartbeat_rscstatus: Allowing a list as expected state to expect multiple OK states
* win_dhcp_pools agent plugin: Filtering additional error message on
systems without dhcp server
diff --git a/checkman/heartbeat_rscstatus b/checkman/heartbeat_rscstatus
index da8fdaa..84c383e 100644
--- a/checkman/heartbeat_rscstatus
+++ b/checkman/heartbeat_rscstatus
@@ -16,5 +16,10 @@ description:
The resource status can be "all", "foreign", "local" or "none.
+[parameters]
+expected_state (string/list): The expected resource status. This can be one expected
+ state as string or multiple expected states given as list. The parameter defaults to
+ the resource status during inventory.
+
inventory:
Each node will get one service from this check.
diff --git a/checks/heartbeat_rscstatus b/checks/heartbeat_rscstatus
index 03a127e..67fe3ee 100644
--- a/checks/heartbeat_rscstatus
+++ b/checks/heartbeat_rscstatus
@@ -35,13 +35,10 @@
def inventory_heartbeat_rscstatus(checktype, info):
return [ (None, '"%s"' % line[0]) for line in info if line[0] != '' ]
-def check_heartbeat_rscstatus(item, expectedState, info):
- if len(info) == 0 or len(info[0]) == 0:
- return (3, "UNKNOWN - Got no data from agent")
-
- if info[0][0] == expectedState:
+def check_heartbeat_rscstatus(item, expected_state, info):
+ if (type(expected_state) == list and info[0][0] in expected_state) or info[0][0] == expected_state:
return (0, "OK - Current state: %s" % (info[0][0]))
else:
- return (2, "CRITICAL - Current state: %s (Expected: %s)" % (info[0][0], expectedState))
+ return (2, "CRITICAL - Current state: %s (Expected: %s)" % (info[0][0], expected_state))
check_info['heartbeat_rscstatus'] = (check_heartbeat_rscstatus, "Heartbeat Ressource Status", 0, inventory_heartbeat_rscstatus)