[Pkg-nagios-changes] [SCM] UNNAMED PROJECT branch, debian/master, updated. 810edbdd3feedbfe37f4a65bee50b57b2f60fa2a
Gerhard Lausser
gerhard.lausser at consol.de
Tue Feb 28 22:21:34 UTC 2012
The following commit has been merged in the debian/master branch:
commit 8f240257f8136e18c67e0d54827ea4a9a7cd26df
Author: Gerhard Lausser <gerhard.lausser at consol.de>
Date: Fri Feb 17 22:19:23 2012 +0100
Add a new testcase, because sven has nothing better to do on a friday evening than to sit at his computer and finding livestatus bugs.
diff --git a/test/test_livestatus_db.py b/test/test_livestatus_db.py
index 4a28292..fb14c9f 100755
--- a/test/test_livestatus_db.py
+++ b/test/test_livestatus_db.py
@@ -76,10 +76,6 @@ class TestConfig(ShinkenTest):
os.remove(self.livelogs)
if os.path.exists(self.livelogs+"-journal"):
os.remove(self.livelogs+"-journal")
- print "i clean up"
- print "i clean up"
- print "i clean up"
- print "i clean up"
if os.path.exists("tmp/archives"):
for db in os.listdir("tmp/archives"):
print "cleanup", db
@@ -708,6 +704,167 @@ OutputFormat: json"""
time.time = fake_time_time
time.sleep = fake_time_sleep
+ def test_a_matching_query(self):
+ #return
+ test_host_005 = self.sched.hosts.find_by_name("test_host_005")
+ test_host_099 = self.sched.hosts.find_by_name("test_host_099")
+ test_ok_00 = self.sched.services.find_srv_by_name_and_hostname("test_host_005", "test_ok_00")
+ test_ok_01 = self.sched.services.find_srv_by_name_and_hostname("test_host_005", "test_ok_01")
+ test_ok_04 = self.sched.services.find_srv_by_name_and_hostname("test_host_005", "test_ok_04")
+ test_ok_16 = self.sched.services.find_srv_by_name_and_hostname("test_host_005", "test_ok_16")
+ test_ok_99 = self.sched.services.find_srv_by_name_and_hostname("test_host_099", "test_ok_01")
+
+ days = 4
+ etime = time.time()
+ print "now it is", time.ctime(etime)
+ print "now it is", time.gmtime(etime)
+ etime_midnight = (etime - (etime % 86400)) + time.altzone
+ print "midnight was", time.ctime(etime_midnight)
+ print "midnight was", time.gmtime(etime_midnight)
+ query_start = etime_midnight - (days - 1) * 86400
+ query_end = etime_midnight
+ print "query_start", time.ctime(query_start)
+ print "query_end ", time.ctime(query_end)
+
+ # |----------|----------|----------|----------|----------|---x
+ # etime
+ # etime_midnight
+ # ---x------
+ # etime - 4 days
+ # |---
+ # query_start
+ #
+ # ............................................
+ # events in the log database ranging till now
+ #
+ # |________________________________|
+ # events which will be read from db
+ #
+ loops = int(86400 / 192)
+ time_warp(-1 * days * 86400)
+ print "warp back to", time.ctime(time.time())
+ # run silently
+ old_stdout = sys.stdout
+ sys.stdout = open(os.devnull, "w")
+ should_be = 0
+ for day in xrange(days):
+ sys.stderr.write("day %d now it is %s i run %d loops\n" % (day, time.ctime(time.time()), loops))
+ self.scheduler_loop(2, [
+ [test_ok_00, 0, "OK"],
+ [test_ok_01, 0, "OK"],
+ [test_ok_04, 0, "OK"],
+ [test_ok_16, 0, "OK"],
+ [test_ok_99, 0, "OK"],
+ ])
+ self.update_broker()
+ #for i in xrange(3600 * 24 * 7):
+ for i in xrange(loops):
+ if i % 10000 == 0:
+ sys.stderr.write(str(i))
+ if i % 399 == 0:
+ self.scheduler_loop(3, [
+ [test_ok_00, 1, "WARN"],
+ [test_ok_01, 2, "CRIT"],
+ [test_ok_04, 3, "UNKN"],
+ [test_ok_16, 1, "WARN"],
+ [test_ok_99, 2, "CRIT"],
+ ])
+ if int(time.time()) >= query_start and int(time.time()) <= query_end:
+ should_be += 3
+ sys.stderr.write("now it should be %s\n" % should_be)
+ time.sleep(62)
+ if i % 399 == 0:
+ self.scheduler_loop(1, [
+ [test_ok_00, 0, "OK"],
+ [test_ok_01, 0, "OK"],
+ [test_ok_04, 0, "OK"],
+ [test_ok_16, 0, "OK"],
+ [test_ok_99, 0, "OK"],
+ ])
+ if int(time.time()) >= query_start and int(time.time()) <= query_end:
+ should_be += 1
+ sys.stderr.write("now it should be %s\n" % should_be)
+ time.sleep(2)
+ if i % 17 == 0:
+ self.scheduler_loop(3, [
+ [test_ok_00, 1, "WARN"],
+ [test_ok_01, 2, "CRIT"],
+ ])
+
+ time.sleep(62)
+ if i % 17 == 0:
+ self.scheduler_loop(1, [
+ [test_ok_00, 0, "OK"],
+ [test_ok_01, 0, "OK"],
+ ])
+ time.sleep(2)
+ if i % 14 == 0:
+ self.scheduler_loop(3, [
+ [test_host_005, 2, "DOWN"],
+ ])
+ if i % 12 == 0:
+ self.scheduler_loop(3, [
+ [test_host_099, 2, "DOWN"],
+ ])
+ time.sleep(62)
+ if i % 14 == 0:
+ self.scheduler_loop(3, [
+ [test_host_005, 0, "UP"],
+ ])
+ if i % 12 == 0:
+ self.scheduler_loop(3, [
+ [test_host_099, 0, "UP"],
+ ])
+ time.sleep(2)
+ self.update_broker()
+ if i % 1000 == 0:
+ self.livestatus_broker.db.commit()
+ endtime = time.time()
+ self.livestatus_broker.db.commit()
+ sys.stderr.write("day %d end it is %s\n" % (day, time.ctime(time.time())))
+ sys.stdout.close()
+ sys.stdout = old_stdout
+ self.livestatus_broker.db.commit_and_rotate_log_db()
+ numlogs = self.livestatus_broker.db.execute("SELECT COUNT(*) FROM logs")
+ print "numlogs is", numlogs
+
+ # now we have a lot of events
+ # find type = HOST ALERT for test_host_005
+ query_end = endtime
+ query_start = query_end - 3600 * 24 * 21
+ request = """GET log
+Columns: class time type state host_name service_description plugin_output message options contact_name command_name state_type current_host_groups current_service_groups
+Filter: time >= """ + str(int(query_start)) + """
+Filter: time <= """ + str(int(query_end)) + """
+And: 2
+Filter: host_name = omd-testsite
+Filter: type = HOST ALERT
+Filter: options ~ ;HARD;
+Filter: type = INITIAL HOST STATE
+Filter: options ~ ;HARD;
+Filter: type = CURRENT HOST STATE
+Filter: options ~ ;HARD;
+Filter: type = HOST DOWNTIME ALERT
+Or: 7
+And: 2
+Filter: host_name = omd-testsite
+Filter: type = SERVICE ALERT
+Filter: options ~ ;HARD;
+Filter: type = INITIAL SERVICE STATE
+Filter: options ~ ;HARD;
+Filter: type = CURRENT SERVICE STATE
+Filter: options ~ ;HARD;
+Filter: type = SERVICE DOWNTIME ALERT
+Or: 7
+And: 2
+Filter: class = 2
+Filter: type ~~ TIMEPERIOD TRANSITION
+Or: 4
+OutputFormat: json
+ResponseHeader: fixed16
+"""
+ response, keepalive = self.livestatus_broker.livestatus.handle_request(request)
+ print response
--
UNNAMED PROJECT
More information about the Pkg-nagios-changes
mailing list