[Pkg-nagios-changes] [SCM] UNNAMED PROJECT branch, debian/master, updated. 810edbdd3feedbfe37f4a65bee50b57b2f60fa2a
Naparuba
naparuba at gmail.com
Tue Feb 28 22:16:08 UTC 2012
The following commit has been merged in the debian/master branch:
commit 17706831d6cfa96814cdc54d20712335780a8098
Author: Naparuba <naparuba at gmail.com>
Date: Tue Jan 24 13:35:29 2012 +0100
*Add : TIMEPERIOD TRANSITION logs from the Arbiter to get timeperiods transition output (for reporting or debug for example)
*Fix : LS create the socket directory if not existing
*Fix : discovery lib, bad disco data type?
diff --git a/shinken/daemons/arbiterdaemon.py b/shinken/daemons/arbiterdaemon.py
index f3eac5a..f6fe78a 100644
--- a/shinken/daemons/arbiterdaemon.py
+++ b/shinken/daemons/arbiterdaemon.py
@@ -562,6 +562,13 @@ class Arbiter(Daemon):
sched.external_commands = []
+ # We will log if there are timeperiods activation
+ # change as NOTICE in logs.
+ def check_and_log_tp_activation_change(self):
+ for tp in self.conf.timeperiods:
+ tp.check_and_log_activation_change()
+
+
# Main function
def run(self):
# Before running, I must be sure who am I
@@ -627,6 +634,10 @@ class Arbiter(Daemon):
# Call modules that manage a starting tick pass
self.hook_point('tick')
+ # Look for logging timeperiods activation change (active/inactive)
+ self.check_and_log_tp_activation_change()
+
+ # Now the dispatcher job
self.dispatcher.check_alive()
self.dispatcher.check_dispatch()
# REF: doc/shinken-conf-dispatching.png (3)
diff --git a/shinken/modules/livestatus_broker/livestatus_broker.py b/shinken/modules/livestatus_broker/livestatus_broker.py
index 83608be..aefc3f9 100644
--- a/shinken/modules/livestatus_broker/livestatus_broker.py
+++ b/shinken/modules/livestatus_broker/livestatus_broker.py
@@ -352,6 +352,9 @@ class LiveStatus_broker(BaseModule, Daemon):
if self.socket:
if os.path.exists(self.socket):
os.remove(self.socket)
+ # I f the socket dir is not existing, create it
+ if not os.path.exists(os.path.dirname(self.socket)):
+ os.mkdir(os.path.dirname(self.socket))
os.umask(0)
sock = socket.socket(socket.AF_UNIX, socket.SOCK_STREAM)
sock.setblocking(0)
diff --git a/shinken/objects/discoveryrule.py b/shinken/objects/discoveryrule.py
index 3ebf7bd..abe8ff4 100644
--- a/shinken/objects/discoveryrule.py
+++ b/shinken/objects/discoveryrule.py
@@ -165,7 +165,7 @@ class Discoveryrule(Item):
for m in self.matches:
#print "Compare to", m
match_one = False
- for (k, v) in datas:
+ for (k, v) in datas.iteritems():
# We found at least one of our match key
if m == k:
if self.is_matching(k, v):
@@ -183,7 +183,7 @@ class Discoveryrule(Item):
for m in self.not_matches:
#print "Compare to NOT", m
match_one = False
- for (k, v) in datas:
+ for (k, v) in datas.iteritems():
#print "K,V", k,v
# We found at least one of our match key
if m == k:
diff --git a/shinken/objects/timeperiod.py b/shinken/objects/timeperiod.py
index 74c241a..effef64 100644
--- a/shinken/objects/timeperiod.py
+++ b/shinken/objects/timeperiod.py
@@ -78,7 +78,8 @@ from item import Item, Items
from shinken.daterange import Daterange, CalendarDaterange, StandardDaterange, MonthWeekDayDaterange
from shinken.daterange import MonthDateDaterange, WeekDayDaterange, MonthDayDaterange
from shinken.brok import Brok
-from shinken.property import IntegerProp, StringProp, ListProp
+from shinken.property import IntegerProp, StringProp, ListProp, BoolProp
+from shinken.log import logger
class Timeperiod(Item):
@@ -95,6 +96,7 @@ class Timeperiod(Item):
# These are needed if a broker module calls methods on timeperiod objects
'dateranges': ListProp (fill_brok=['full_status'], default=[]),
'exclude': ListProp (fill_brok=['full_status'], default=[]),
+ 'is_active': BoolProp (default='0')
})
@@ -116,10 +118,12 @@ class Timeperiod(Item):
self.cache = {} #For tunning purpose only
self.configuration_errors = []
self.configuration_warnings = []
+ # By default the tp is None so we know we just start
+ self.is_active = None
def get_name(self):
- return self.timeperiod_name
+ return getattr(self, 'timeperiod_name', 'unknown_timeperiod')
#We fillfull properties with template ones if need
@@ -162,6 +166,31 @@ class Timeperiod(Item):
except KeyError:
return None
+ # will look for active/un-active change. And log it
+ # [1327392000] TIMEPERIOD TRANSITION: <name>;<from>;<to>
+ # from is -1 on startup. to is 1 if the timeperiod starts
+ # and 0 if it ends.
+ def check_and_log_activation_change(self):
+ now = int(time.time())
+
+ was_active = self.is_active
+ self.is_active = self.is_time_valid(now)
+
+ # If we got a change, log it!
+ if self.is_active != was_active:
+ _from = 0
+ _to = 0
+ # If it's the start, get a special value for was
+ if was_active is None:
+ _from = -1
+ if was_active:
+ _from = 1
+ if self.is_active:
+ _to = 1
+
+ # Now raise the log
+ logger.log('TIMEPERIOD TRANSITION: %s;%d;%d' % (self.get_name(), _from, _to))
+
# clean the get_next_valid_time_from_t cache
# The entries are a dict on t. t < now are useless
diff --git a/test/jenkins/longtests.txt b/test/jenkins/longtests.txt
index 3ab862d..d713d5f 100644
--- a/test/jenkins/longtests.txt
+++ b/test/jenkins/longtests.txt
@@ -89,6 +89,7 @@ test_dot_virg_in_command.py
test_bad_escalation_on_groups.py
test_no_host_template.py
test_notif_too_much.py
+test_timeperiods_state_logs.py
test_groups_with_no_alias.py
test_parse_perfdata.py
diff --git a/test/jenkins/shorttests.txt b/test/jenkins/shorttests.txt
index f317918..d3b50ee 100644
--- a/test/jenkins/shorttests.txt
+++ b/test/jenkins/shorttests.txt
@@ -97,4 +97,5 @@ test_bad_escalation_on_groups.py
test_no_host_template.py
test_notif_too_much.py
test_groups_with_no_alias.py
+test_timeperiods_state_logs.py
test_parse_perfdata.py
diff --git a/test/quick_tests.sh b/test/quick_tests.sh
index 5e2174a..b7c8100 100755
--- a/test/quick_tests.sh
+++ b/test/quick_tests.sh
@@ -135,6 +135,7 @@ launch_and_assert test_bad_escalation_on_groups.py
launch_and_assert test_no_host_template.py
launch_and_assert test_groups_with_no_alias.py
launch_and_assert test_notif_too_much.py
+launch_and_assert test_timeperiods_state_logs.py
launch_and_assert test_maintenance_period.py
#Live status is a bit longer than the previous, so we put it at the end.
diff --git a/test/test_groups_with_no_alias.py b/test/test_timeperiods_state_logs.py
similarity index 52%
copy from test/test_groups_with_no_alias.py
copy to test/test_timeperiods_state_logs.py
index dc64457..d1fb401 100755
--- a/test/test_groups_with_no_alias.py
+++ b/test/test_timeperiods_state_logs.py
@@ -26,31 +26,37 @@
from shinken_test import *
-class TestGroupwithNoAlias(ShinkenTest):
+class TestTPStateLog(ShinkenTest):
#Uncomment this is you want to use a specific configuration
#for your test
- def setUp(self):
- self.setup_with_file('etc/nagios_groups_with_no_alias.cfg')
+ #def setUp(self):
+ # self.setup_with_file('etc/nagios_timeperiods_state_logs.cfg')
- #Change ME :)
- def test_look_for_alias(self):
- #
- # Config is not correct because of a wrong relative path
- # in the main config file
- #
- print "Get the hosts and services"
+ # A timeperiod state change should raise a log, and only when change.
+ def test_tp_state_log(self):
now = time.time()
- hg = self.sched.hostgroups.find_by_name("NOALIAS")
- self.assert_(hg is not None)
- print hg.__dict__
- self.assert_(hg.alias == "NOALIAS")
-
- sg = self.sched.servicegroups.find_by_name("NOALIAS")
- self.assert_(sg is not None)
- print sg.__dict__
- self.assert_(sg.alias == "NOALIAS")
+ tp = self.sched.timeperiods.find_by_name('24x7')
+
+ self.assert_(tp is not None)
+ tp.check_and_log_activation_change()
+ self.assert_(self.any_log_match("TIMEPERIOD TRANSITION: 24x7;-1;1"))
+ self.show_and_clear_logs()
+ # Now make this tp unable to be active again by removing al it's daterange :p
+ dr = tp.dateranges
+ tp.dateranges = []
+ tp.check_and_log_activation_change()
+ self.assert_(self.any_log_match("TIMEPERIOD TRANSITION: 24x7;1;0"))
+ self.show_and_clear_logs()
+
+ # Ok, let get back to work :)
+ tp.dateranges = dr
+ tp.check_and_log_activation_change()
+ self.assert_(self.any_log_match("TIMEPERIOD TRANSITION: 24x7;0;1"))
+ self.show_and_clear_logs()
+
+
if __name__ == '__main__':
unittest.main()
--
UNNAMED PROJECT
More information about the Pkg-nagios-changes
mailing list