Module: check_mk
Branch: master
Commit: cd3ba3c7b7d59d8bc1cc06bcba1c08ce9ff4775a
URL: http://git.mathias-kettner.de/git/?p=check_mk.git;a=commit;h=cd3ba3c7b7d59d…
Author: Lars Michelsen <lm(a)mathias-kettner.de>
Date: Thu Sep 5 14:03:54 2013 +0200
Trying to reduce some frequent IO calls (check file exists in advance to reads)
---
web/htdocs/userdb.py | 135 +++++++++++++++++++++++++++-----------------------
1 file changed, 73 insertions(+), 62 deletions(-)
diff --git a/web/htdocs/userdb.py b/web/htdocs/userdb.py
index 6ceb8d0..2e9b55e 100644
--- a/web/htdocs/userdb.py
+++ b/web/htdocs/userdb.py
@@ -187,10 +187,12 @@ def get_user_attributes():
def load_users(lock = False):
filename = root_dir + "contacts.mk"
- # Make sure that the file exists without modifying it, *if* it exists.
- # Note: the lock will be released at end of page request automatically.
- file(filename, "a")
if lock:
+ # Make sure that the file exists without modifying it, *if* it exists
+ # to be able to lock and realease the file properly.
+ # Note: the lock will be released on next save_users() call or at
+ # end of page request automatically.
+ file(filename, "a")
aquire_lock(filename)
# First load monitoring contacts from Check_MK's world. If this is
@@ -200,6 +202,8 @@ def load_users(lock = False):
vars = { "contacts" : {} }
execfile(filename, vars, vars)
contacts = vars["contacts"]
+ except IOError:
+ contacts = {} # a not existing file is ok, start with empty data
except Exception, e:
if config.debug:
raise MKGeneralException(_("Cannot read configuration file %s: %s" %
@@ -211,20 +215,19 @@ def load_users(lock = False):
# Now add information about users from the Web world
filename = multisite_dir + "users.mk"
- if os.path.exists(filename):
- try:
- vars = { "multisite_users" : {} }
- execfile(filename, vars, vars)
- users = vars["multisite_users"]
- except Exception, e:
- if config.debug:
- raise MKGeneralException(_("Cannot read configuration file %s: %s" %
- (filename, e)))
- else:
- html.log('load_users: Problem while loading users (%s - %s). '
- 'Initializing structure...' % (filename, e))
- users = {}
- else:
+ try:
+ vars = { "multisite_users" : {} }
+ execfile(filename, vars, vars)
+ users = vars["multisite_users"]
+ except IOError:
+ users = {} # not existing is ok -> empty structure
+ except Exception, e:
+ if config.debug:
+ raise MKGeneralException(_("Cannot read configuration file %s: %s" %
+ (filename, e)))
+ else:
+ html.log('load_users: Problem while loading users (%s - %s). '
+ 'Initializing structure...' % (filename, e))
users = {}
# Merge them together. Monitoring users not known to Multisite
@@ -252,41 +255,45 @@ def load_users(lock = False):
# they are getting according to the multisite old-style
# configuration variables.
+ def readlines(f):
+ try:
+ return file(f)
+ except IOError:
+ return []
+
filename = defaults.htpasswd_file
- if os.path.exists(filename):
- for line in file(filename):
- line = line.strip()
- if ':' in line:
- id, password = line.strip().split(":")[:2]
- if password.startswith("!"):
- locked = True
- password = password[1:]
- else:
- locked = False
- if id in result:
- result[id]["password"] = password
- result[id]["locked"] = locked
- else:
- # Create entry if this is an admin user
- new_user = {
- "roles" : config.roles_of_user(id),
- "password" : password,
- "locked" : False,
- }
- result[id] = new_user
- # Make sure that the user has an alias
- result[id].setdefault("alias", id)
- # Other unknown entries will silently be dropped. Sorry...
+ for line in readlines(filename):
+ line = line.strip()
+ if ':' in line:
+ id, password = line.strip().split(":")[:2]
+ if password.startswith("!"):
+ locked = True
+ password = password[1:]
+ else:
+ locked = False
+ if id in result:
+ result[id]["password"] = password
+ result[id]["locked"] = locked
+ else:
+ # Create entry if this is an admin user
+ new_user = {
+ "roles" : config.roles_of_user(id),
+ "password" : password,
+ "locked" : False,
+ }
+ result[id] = new_user
+ # Make sure that the user has an alias
+ result[id].setdefault("alias", id)
+ # Other unknown entries will silently be dropped. Sorry...
# Now read the serials, only process for existing users
serials_file = '%s/auth.serials' % os.path.dirname(defaults.htpasswd_file)
- if os.path.exists(serials_file):
- for line in file(serials_file):
- line = line.strip()
- if ':' in line:
- user_id, serial = line.split(':')[:2]
- if user_id in result:
- result[user_id]['serial'] = saveint(serial)
+ for line in readlines(serials_file):
+ line = line.strip()
+ if ':' in line:
+ user_id, serial = line.split(':')[:2]
+ if user_id in result:
+ result[user_id]['serial'] = saveint(serial)
# Now read the user specific files
dir = defaults.var_dir + "/web/"
@@ -296,15 +303,19 @@ def load_users(lock = False):
# read special values from own files
for val, conv_func in [ ('num_failed', int), ('last_seen', float) ]:
- path = dir + d + '/' + val + '.mk'
- if id in result and os.path.exists(path):
- result[id][val] = conv_func(file(path).read().strip())
+ if id in result:
+ try:
+ result[id][val] = conv_func(file(dir + d + '/' + val + '.mk').read().strip())
+ except IOError:
+ pass
# read automation secrets and add them to existing
# users or create new users automatically
- secret_file = dir + d + "/automation.secret"
- if os.path.exists(secret_file):
- secret = file(secret_file).read().strip()
+ try:
+ secret = file(dir + d + "/automation.secret").read().strip()
+ except IOError:
+ secret = None
+ if secret:
if id in result:
result[id]["automation_secret"] = secret
else:
@@ -467,9 +478,6 @@ def load_roles():
for id in config.builtin_role_ids ])
filename = multisite_dir + "roles.mk"
- if not os.path.exists(filename):
- return roles
-
try:
vars = { "roles" : roles }
execfile(filename, vars, vars)
@@ -489,6 +497,8 @@ def load_roles():
return vars["roles"]
+ except IOError:
+ return roles # Use empty structure, not existing file is ok!
except Exception, e:
if config.debug:
raise MKGeneralException(_("Cannot read configuration file %s: %s" %
@@ -509,15 +519,16 @@ def load_roles():
def load_group_information():
try:
- filename = root_dir + "groups.mk"
- if not os.path.exists(filename):
- return {}
-
vars = {}
for what in ["host", "service", "contact" ]:
vars["define_%sgroups" % what] = {}
- execfile(filename, vars, vars)
+ filename = root_dir + "groups.mk"
+ try:
+ execfile(filename, vars, vars)
+ except IOError:
+ return {} # skip on not existing file
+
groups = {}
for what in ["host", "service", "contact" ]:
groups[what] = vars.get("define_%sgroups" % what, {})
Module: check_mk
Branch: master
Commit: ac58bcf21bfc6c43d10ab08a814a1f78e0ecd178
URL: http://git.mathias-kettner.de/git/?p=check_mk.git;a=commit;h=ac58bcf21bfc6c…
Author: Lars Michelsen <lm(a)mathias-kettner.de>
Date: Fri Sep 6 14:47:03 2013 +0200
cisco_qos: Updated to be able to mintor IOS XR 4.2.1 (on a ASR9K device)
---
ChangeLog | 2 ++
checks/cisco_qos | 71 ++++++++++++++++++++++++++++++++++--------------------
2 files changed, 47 insertions(+), 26 deletions(-)
diff --git a/ChangeLog b/ChangeLog
index 8fa6364..d2d6cec 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -72,10 +72,12 @@
* cisco_wlc_clients: New check for the nummber of clients in a wlc wifi
* df: Negative integer levels for MB left on a device
* win_printers: Monitoring of printer queue on a windows printserver
+ * cisco_qos: Updated to be able to mintor IOS XR 4.2.1 (on a ASR9K device)
* FIX: hr_mem: handle virtual memory correct on some devices
* FIX: apache_status agent plugin: now also works, if prog name contains slashes
* FIX: check_dns: parameter -A does not get an additional string
* FIX: cisco_qos: Catch policies without post/drop byte information
+ * FIX: cisco_qos: Catch policies without individual bandwidth limits
Notifications:
* notify.py: Matching service level: Use the hosts service level if a
diff --git a/checks/cisco_qos b/checks/cisco_qos
index bc26568..7d2e092 100644
--- a/checks/cisco_qos
+++ b/checks/cisco_qos
@@ -45,20 +45,20 @@
# TEST:
#
# search class table:
-# .1.3.6.1.4.1.9.9.166.1.7.1.1.1.284945 "AF1"
-# class_id = 284945
+# .1.3.6.1.4.1.9.9.166.1.7.1.1.1.284945 (cbQosCMName) "AF1"
+# class_id = 284945 (cbQosConfigIndex)
#
# search config table for matching value
# .1.3.6.1.4.1.9.9.166.1.5.1.1.2.144.5256 284945
-# key = 144.5256
+# key = 144.5256 (cbQosPolicyIndex: 144, cbQosObjectsIndex: 5256)
#
# search if table for matchin if_id: 144
-# .1.3.6.1.4.1.9.9.166.1.1.1.1.4.144 9
-# if_policy = 9
+# .1.3.6.1.4.1.9.9.166.1.1.1.1.4.144 (cbQosIfIndex) 9
+# if_policy = 9 (ifIndex -> standard mib)
#
-# get policy_id from config table using if_id.if_id 144.144
-# .1.3.6.1.4.1.9.9.166.1.5.1.1.2.144.144 6208592
-# policy_index = 6208592
+# get config_id from config table using if_id.if_id 144.144
+# .1.3.6.1.4.1.9.9.166.1.5.1.1.2.144.144 (cbQosConfigIndex) 6208592
+# config_index = 6208592
#
# get policy name using the policy_index
# .1.3.6.1.4.1.9.9.166.1.6.1.1.1.6208592 "ingress-map"
@@ -122,7 +122,7 @@ cisco_qos_default_levels = (None, None, 0.01, 0.01)
# "drop" : (0.01, 0.01)
#}
-def cisco_qos_get_ifs_by_class_id(config, class_id):
+def cisco_qos_get_config_entries_by_class_id(config, class_id):
return [ if_index.split('.') for if_index, value in config.iteritems() if value == class_id ]
def inventory_cisco_qos(info):
@@ -135,8 +135,8 @@ def inventory_cisco_qos(info):
items = []
for class_id, class_name in info[2]:
# Get interface ids which use this qos class
- for policy_if_id, policy_if_id2 in cisco_qos_get_ifs_by_class_id(config, class_id):
- if_name = if_names[ifs[policy_if_id]]
+ for policy_id, objects_id in cisco_qos_get_config_entries_by_class_id(config, class_id):
+ if_name = if_names[ifs[policy_id]]
items += [ ('%s: %s' % (if_name, class_name), {}) ]
return items
@@ -169,7 +169,7 @@ def check_cisco_qos(item, params, info):
if_speeds = dict(info[7])
parents = dict(info[8])
if_qos_bandwidth = dict(info[9])
- parents_type = dict(info[10])
+ object_types = dict(info[10])
if_name, class_name = item.split(': ')
@@ -190,19 +190,35 @@ def check_cisco_qos(item, params, info):
if not if_id or not class_id:
return (3, "QoS class not found for that interface")
- # Gather information for this object
- policy_if_id, policy_if_id2 = cisco_qos_get_ifs_by_class_id(config, class_id)[0]
- try:
- policy_id = config[policy_if_id+'.'+policy_if_id]
- except KeyError:
- # Be compatible with newer IOS-XE releases where the last digit is pinned
- # to "1" instead of the plicy_if_id
- policy_id = config[policy_if_id+'.1']
- policy_name = policies[policy_id]
- post_b = post_bytes.get(policy_if_id+'.'+policy_if_id2, 0)
- drop_b = drop_bytes.get(policy_if_id+'.'+policy_if_id2, 0)
+ policy_id, objects_id, policy_map_id, policy_name = None, None, None, None
+ for this_policy_id, this_objects_id in cisco_qos_get_config_entries_by_class_id(config, class_id):
+ if if_id != ifs[this_policy_id]:
+ continue # skip the ones of other interfaces
+
+ # Get the policy_map_id. To retrieve this get one of the config entries
+ # of type "policy map" from the config table. All of this type should have
+ # the same value, which is then the policy_map_id.
+ for key in object_types.keys():
+ if key.startswith(this_policy_id+'.') and object_types[key] == '1':
+ policy_map_id = config[key]
+ break
+
+ if policy_map_id is None:
+ return 3, 'Invalid policy map id'
+
+ policy_name = policies[policy_map_id]
+ policy_id = this_policy_id
+ objects_id = this_objects_id
+
+ if policy_id is None or objects_id is None:
+ return 3, 'Could not find policy_id or objects_id'
+
+ post_b = post_bytes.get(policy_id+'.'+objects_id, 0)
+ drop_b = drop_bytes.get(policy_id+'.'+objects_id, 0)
speed = saveint(if_speeds[if_id])
+ # might not have a specific speed. Skip these.
+ # FIXME: Maybe ignore speed checking on them or similar - does it make sense?
speed_found = False
for a_key, a_value in config.items():
if speed_found:
@@ -211,9 +227,12 @@ def check_cisco_qos(item, params, info):
parent_value = a_key.split(".")[1]
for b_key, b_value in parents.items():
if parent_value == b_value:
- if parents_type[b_key] == "4":
- speed = saveint(if_qos_bandwidth[config[b_key]]) * 1000
- speed_found = True
+ if object_types[b_key] == "4":
+ try:
+ speed = saveint(if_qos_bandwidth[config[b_key]]) * 1000
+ speed_found = True
+ except KeyError:
+ pass
# Bandwidth needs to be in bytes for later calculations
bw = speed / 8.0
Module: check_mk
Branch: master
Commit: d84d542c25d1692146332441592b9f4e51f6957c
URL: http://git.mathias-kettner.de/git/?p=check_mk.git;a=commit;h=d84d542c25d169…
Author: Bernd Stroessenreuther <bs(a)mathias-kettner.de>
Date: Fri Sep 6 14:33:01 2013 +0200
Updated bug entries #0902
---
.bugs/902 | 7 +++++++
1 file changed, 7 insertions(+)
diff --git a/.bugs/902 b/.bugs/902
index 679a62c..90654ba 100644
--- a/.bugs/902
+++ b/.bugs/902
@@ -12,3 +12,10 @@ Looks like a file creation/permission problem in directory
If I mkdir /var/lib/check_mk/notify and chmod nagios.nagios
/var/lib/check_mk/notify it works.
Environment: check_mk 1.2.0p3, 1.2.2b1, ubuntu 12.10
+
+2013-09-06 bs: Bug approved
+when installing check_mk-1.2.2p1 manually (by setup.sh) the directory
+/var/lib/check_mk/notify is not created
+and as long as this directory is missing *all* notifications fail
+silently!!
+directory needs to be created in setup.sh
Module: check_mk
Branch: master
Commit: 6657a3a1c7aa976d0c44e347e752832bade592f2
URL: http://git.mathias-kettner.de/git/?p=check_mk.git;a=commit;h=6657a3a1c7aa97…
Author: Bernd Stroessenreuther <bs(a)mathias-kettner.de>
Date: Fri Sep 6 09:41:16 2013 +0200
Updated bug entries #1040, #1047
---
.bugs/1040 | 8 +++++---
.bugs/1047 | 10 ++++++++++
2 files changed, 15 insertions(+), 3 deletions(-)
diff --git a/.bugs/1040 b/.bugs/1040
index 77b6900..fc514c3 100644
--- a/.bugs/1040
+++ b/.bugs/1040
@@ -1,9 +1,9 @@
Title: job directory should be created with mode 1777
Component: core
-State: open
+Class: nastiness
+State: done
Date: 2013-08-30 10:58:02
Targetversion: 1.2.3i2
-Class: nastiness
/var/lib/check_mk_agent/job directory is created root.root 755 now
this way only cronjobs running under root can use mk-job
@@ -17,4 +17,6 @@ delete his own files
integrated directives in .spec file
test of rpm packages done
test of deb packaged done
-on CentOS mk-job probably needs package time to have /usr/bin/time available -> to be approved
+
+2013-09-06 09:41:08: changed state open -> done
+fixed
diff --git a/.bugs/1047 b/.bugs/1047
new file mode 100644
index 0000000..41f186e
--- /dev/null
+++ b/.bugs/1047
@@ -0,0 +1,10 @@
+Title: check-mk-agent package needs dependency to time package
+Component: checks
+State: open
+Date: 2013-09-06 09:36:53
+Targetversion: 1.2.3i2
+Class: bug
+
+mk-job uses /usr/bin/time
+this is included in package time (as well in CentOS as in Ubuntu)
+package should require package time
Module: check_mk
Branch: master
Commit: 51bff858794f21648587ccafc44e74cb8e078526
URL: http://git.mathias-kettner.de/git/?p=check_mk.git;a=commit;h=51bff858794f21…
Author: Bernd Stroessenreuther <bs(a)mathias-kettner.de>
Date: Thu Sep 5 17:07:10 2013 +0200
Updated bug entries #1040
---
.bugs/1040 | 5 +++++
1 file changed, 5 insertions(+)
diff --git a/.bugs/1040 b/.bugs/1040
index ff22227..e1cd46b 100644
--- a/.bugs/1040
+++ b/.bugs/1040
@@ -12,3 +12,8 @@ directory should be created with mode 1777 so cronjobs running under unprivilege
users can write their files into this directory too
this should be no security problem, because the t bit makes sure, every user can only
delete his own files
+
+2013-09-05 bs:
+integrated directives in .spec file
+test of rpm packages done
+test of deb packaged tbd