1 #!/usr/bin/env python2.6
2 # -*- coding: utf-8 -*-
4 #Copyright (C) 2009-2010 :
5 # Gabes Jean, naparuba@gmail.com
6 # Gerhard Lausser, Gerhard.Lausser@consol.de
8 #This file is part of Shinken.
10 #Shinken is free software: you can redistribute it and/or modify
11 #it under the terms of the GNU Affero General Public License as published by
12 #the Free Software Foundation, either version 3 of the License, or
13 #(at your option) any later version.
15 #Shinken is distributed in the hope that it will be useful,
16 #but WITHOUT ANY WARRANTY; without even the implied warranty of
17 #MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 #GNU Affero General Public License for more details.
20 #You should have received a copy of the GNU Affero General Public License
21 #along with Shinken. If not, see <http://www.gnu.org/licenses/>.
25 # This file is used to test host- and service-downtimes.
28 from shinken_test
import *
37 from shinken
.brok
import Brok
38 from shinken
.objects
.timeperiod
import Timeperiod
39 from shinken
.objects
.module
import Module
40 from shinken
.comment
import Comment
42 from shinken
.modules
import livestatus_broker
43 from shinken
.modules
.livestatus_broker
import Livestatus_broker
45 sys
.setcheckinterval(10000)
48 modconf
.module_name
= "livestatus"
49 modconf
.module_type
= livestatus_broker
.properties
['type']
50 modconf
.properties
= livestatus_broker
.properties
.copy()
52 class TestConfig(ShinkenTest
):
53 def contains_line(self
, text
, pattern
):
54 regex
= re
.compile(pattern
)
55 for line
in text
.splitlines():
56 if re
.search(regex
, line
):
61 def scheduler_loop(self
, count
, reflist
, do_sleep
=False, sleep_time
=61):
62 super(TestConfig
, self
).scheduler_loop(count
, reflist
, do_sleep
, sleep_time
)
63 if self
.nagios_installed() and hasattr(self
, 'nagios_started'):
64 self
.nagios_loop(1, reflist
)
67 def update_broker(self
, dodeepcopy
=False):
68 #The brok should be manage in the good order
69 ids
= self
.sched
.broks
.keys()
72 brok
= self
.sched
.broks
[brok_id
]
73 #print "Managing a brok type", brok.type, "of id", brok_id
74 #if brok.type == 'update_service_status':
75 # print "Problem?", brok.data['is_problem']
77 brok
= copy
.deepcopy(brok
)
78 self
.livestatus_broker
.manage_brok(brok
)
82 def lines_equal(self
, text1
, text2
):
83 # gets two multiline strings and compares the contents
84 # lifestatus output may not be in alphabetical order, so this
85 # function is used to compare unordered output with unordered
87 # sometimes mklivestatus returns 0 or 1 on an empty result
88 text1
= text1
.replace("200 1", "200 0")
89 text2
= text2
.replace("200 1", "200 0")
90 text1
= text1
.rstrip()
91 text2
= text2
.rstrip()
92 #print "text1 //%s//" % text1
93 #print "text2 //%s//" % text2
94 sorted1
= "\n".join(sorted(text1
.split("\n")))
95 sorted2
= "\n".join(sorted(text2
.split("\n")))
96 len1
= len(text1
.split("\n"))
97 len2
= len(text2
.split("\n"))
98 #print "%s == %s text cmp %s" % (len1, len2, sorted1 == sorted2)
99 #print "text1 //%s//" % sorted(text1.split("\n"))
100 #print "text2 //%s//" % sorted(text2.split("\n"))
101 if sorted1
== sorted2
and len1
== len2
:
104 # Maybe list members are different
105 # allhosts;test_host_0;test_ok_0;servicegroup_02,servicegroup_01,ok
106 # allhosts;test_host_0;test_ok_0;servicegroup_02,ok,servicegroup_01
108 # [['allhosts'], ['test_host_0'], ['test_ok_0'],
109 # ['ok', 'servicegroup_01', 'servicegroup_02']]
110 [line
for line
in sorted(text1
.split("\n"))]
111 data1
= [[sorted(c
.split(',')) for c
in columns
] for columns
in [line
.split(';') for line
in sorted(text1
.split("\n")) if line
]]
112 data2
= [[sorted(c
.split(',')) for c
in columns
] for columns
in [line
.split(';') for line
in sorted(text2
.split("\n")) if line
]]
113 #print "text1 //%s//" % data1
114 #print "text2 //%s//" % data2
115 # cmp is clever enough to handle nested arrays
116 return cmp(data1
, data2
) == 0
119 def show_broks(self
, title
):
122 for brok
in sorted(self
.sched
.broks
.values(), lambda x
, y
: x
.id - y
.id):
123 if re
.compile('^service_').match(brok
.type):
124 print "BROK:", brok
.type
125 print "BROK ", brok
.data
['in_checking']
127 request
= 'GET services\nColumns: service_description is_executing\n'
128 response
, keepalive
= self
.livestatus_broker
.livestatus
.handle_request(request
)
132 def nagios_installed(self
, path
='/usr/local/nagios/bin/nagios', livestatus
='/usr/local/nagios/lib/mk-livestatus/livestatus.o'):
135 if os
.path
.exists(path
) and os
.access(path
, os
.X_OK
) and os
.path
.exists(livestatus
):
136 self
.nagios_path
= path
137 self
.livestatus_path
= livestatus
143 # shinkenize_nagios_config('nagios_1r_1h_1s')
144 # We assume that there is a nagios_1r_1h_1s.cfg and a nagios_1r_1h_1s directory for the objects
145 def unshinkenize_config(self
, configname
):
146 new_configname
= configname
+ '_' + str(os
.getpid())
147 config
= open('etc/nagios_' + configname
+ '.cfg')
148 text
= config
.readlines()
151 newconfig
= open('etc/nagios_' + new_configname
+ '.cfg', 'w')
153 if re
.search('^resource_file=', line
):
154 newconfig
.write("resource_file=etc/resource.cfg\n")
155 elif re
.search('shinken\-specific\.cfg', line
):
157 elif re
.search('enable_problem_impacts_states_change', line
):
159 elif re
.search('cfg_dir=', line
):
160 newconfig
.write(re
.sub(configname
, new_configname
, line
))
161 elif re
.search('cfg_file=', line
):
162 newconfig
.write(re
.sub(configname
, new_configname
, line
))
163 elif re
.search('execute_host_checks=', line
):
164 newconfig
.write("execute_host_checks=0\n")
165 elif re
.search('execute_service_checks=', line
):
166 newconfig
.write("execute_service_checks=0\n")
167 elif re
.search('^debug_level=', line
):
168 newconfig
.write("debug_level=0\n")
169 elif re
.search('^debug_verbosity=', line
):
170 newconfig
.write("debug_verbosity=0\n")
171 elif re
.search('^status_update_interval=', line
):
172 newconfig
.write("status_update_interval=30\n")
173 elif re
.search('^command_file=', line
):
174 newconfig
.write("command_file=var/nagios.cmd\n")
175 elif re
.search('^command_check_interval=', line
):
176 newconfig
.write("command_check_interval=1s\n")
178 newconfig
.write(line
)
179 newconfig
.write('broker_module=/usr/local/nagios/lib/mk-livestatus/livestatus.o var/live' + "\n")
181 for dirfile
in os
.walk('etc/' + configname
):
182 dirpath
, dirlist
, filelist
= dirfile
183 newdirpath
= re
.sub(configname
, new_configname
, dirpath
)
185 for file in [f
for f
in filelist
if re
.search('\.cfg$', f
)]:
186 config
= open(dirpath
+ '/' + file)
187 text
= config
.readlines()
189 newconfig
= open(newdirpath
+ '/' + file, 'w')
191 if re
.search('^\s*criticity', line
):
193 elif re
.search('enable_problem_impacts_states_change', line
):
196 newconfig
.write(line
)
198 return new_configname
201 def start_nagios(self
, config
):
202 if os
.path
.exists('var/spool/checkresults'):
203 # Cleanup leftover checkresults
204 shutil
.rmtree('var/spool/checkresults')
205 for dir in ['tmp', 'var/tmp', 'var/spool', 'var/spool/checkresults', 'var/archives']:
206 if not os
.path
.exists(dir):
208 self
.nagios_config
= self
.unshinkenize_config(config
)
209 if os
.path
.exists('var/nagios.log'):
210 os
.remove('var/nagios.log')
211 if os
.path
.exists('var/retention.dat'):
212 os
.remove('var/retention.dat')
213 if os
.path
.exists('var/status.dat'):
214 os
.remove('var/status.dat')
215 self
.nagios_proc
= subprocess
.Popen([self
.nagios_path
, 'etc/nagios_' + self
.nagios_config
+ '.cfg'], close_fds
=True)
216 self
.nagios_started
= time
.time()
220 def stop_nagios(self
):
221 if self
.nagios_installed():
222 print "i stop nagios!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!"
224 if hasattr(self
, 'nagios_proc'):
226 while self
.nagios_proc
.poll() is None and attempt
< 4:
227 self
.nagios_proc
.terminate()
230 if self
.nagios_proc
.poll() is None:
231 self
.nagios_proc
.kill()
232 if os
.path
.exists('etc/' + self
.nagios_config
):
233 shutil
.rmtree('etc/' + self
.nagios_config
)
234 if os
.path
.exists('etc/nagios_' + self
.nagios_config
+ '.cfg'):
235 os
.remove('etc/nagios_' + self
.nagios_config
+ '.cfg')
238 def ask_nagios(self
, request
):
239 if time
.time() - self
.nagios_started
< 2:
241 if not request
.endswith("\n"):
242 request
= request
+ "\n"
243 unixcat
= subprocess
.Popen([os
.path
.dirname(self
.nagios_path
) + '/' + 'unixcat', 'var/live'], stdin
=subprocess
.PIPE
, stdout
=subprocess
.PIPE
, stderr
=subprocess
.PIPE
)
245 out
, err
= unixcat
.communicate(request
)
247 print "mklivestatus duration %f" % (tac
- tic
)
249 while unixcat
.poll() is None and attempt
< 4:
253 if unixcat
.poll() is None:
255 print "unixcat says", out
259 def nagios_loop(self
, count
, reflist
, do_sleep
=False, sleep_time
=61):
261 buffer = open('var/pipebuffer', 'w')
263 (obj
, exit_status
, output
) = ref
264 if obj
.my_type
== 'service':
265 cmd
= "[%lu] PROCESS_SERVICE_CHECK_RESULT;%s;%s;%d;%s\n" % (now
, obj
.host_name
, obj
.service_description
, exit_status
, output
)
269 cmd
= "[%lu] PROCESS_HOST_CHECK_RESULT;%s;%d;%s\n" % (now
, obj
.host_name
, exit_status
, output
)
272 print "open pipe", self
.conf
.command_file
273 fifo
= open('var/nagios.cmd', 'w')
274 cmd
= "[%lu] PROCESS_FILE;%s;0\n" % (now
, 'var/pipebuffer')
281 def nagios_extcmd(self
, cmd
):
282 fifo
= open('var/nagios.cmd', 'w')
290 class TestConfigSmall(TestConfig
):
292 self
.setup_with_file('etc/nagios_1r_1h_1s.cfg')
294 self
.testid
= str(os
.getpid() + random
.randint(1, 1000))
295 self
.livelogs
= 'tmp/livelogs.db' + self
.testid
296 self
.pnp4nagios
= 'tmp/pnp4nagios_test' + self
.testid
297 self
.livestatus_broker
= Livestatus_broker(modconf
, '127.0.0.1', str(50000 + os
.getpid()), 'live', [], self
.livelogs
, 365, self
.pnp4nagios
)
298 self
.livestatus_broker
.create_queues()
299 #self.livestatus_broker.properties = {
304 self
.livestatus_broker
.init()
305 print "Cleaning old broks?"
306 self
.sched
.fill_initial_broks()
308 self
.nagios_path
= None
309 self
.livestatus_path
= None
310 self
.nagios_config
= None
316 self
.livestatus_broker
.dbconn
.commit()
317 self
.livestatus_broker
.dbconn
.close()
318 if os
.path
.exists(self
.livelogs
):
319 os
.remove(self
.livelogs
)
320 if os
.path
.exists(self
.pnp4nagios
):
321 shutil
.rmtree(self
.pnp4nagios
)
322 if os
.path
.exists('var/nagios.log'):
323 os
.remove('var/nagios.log')
324 if os
.path
.exists('var/retention.dat'):
325 os
.remove('var/retention.dat')
326 if os
.path
.exists('var/status.dat'):
327 os
.remove('var/status.dat')
330 def test_childs(self
):
331 if self
.nagios_installed():
332 self
.start_nagios('1r_1h_1s')
336 for host
in self
.sched
.hosts
:
337 objlist
.append([host
, 0, 'UP'])
338 for service
in self
.sched
.services
:
339 objlist
.append([service
, 0, 'OK'])
340 self
.scheduler_loop(1, objlist
)
342 request
= """GET hosts
344 Filter: name = test_host_0
347 ResponseHeader: fixed16
349 response
, keepalive
= self
.livestatus_broker
.livestatus
.handle_request(request
)
351 if self
.nagios_installed():
352 nagresponse
= self
.ask_nagios(request
)
353 print "nagresponse----------------------------------------------"
355 self
.assert_(self
.lines_equal(response
, nagresponse
))
356 request
= """GET hosts
358 Filter: name = test_router_0
361 ResponseHeader: fixed16
363 response
, keepalive
= self
.livestatus_broker
.livestatus
.handle_request(request
)
365 if self
.nagios_installed():
366 nagresponse
= self
.ask_nagios(request
)
367 print "nagresponse----------------------------------------------"
369 self
.assert_(self
.lines_equal(response
, nagresponse
))
373 def test_servicesbyhostgroup(self
):
374 if self
.nagios_installed():
375 self
.start_nagios('1r_1h_1s')
379 for host
in self
.sched
.hosts
:
380 objlist
.append([host
, 0, 'UP'])
381 for service
in self
.sched
.services
:
382 objlist
.append([service
, 0, 'OK'])
383 self
.scheduler_loop(1, objlist
)
385 request
= """GET servicesbyhostgroup
386 Filter: host_groups >= allhosts
387 Columns: hostgroup_name host_name service_description groups
390 ResponseHeader: fixed16
392 response
, keepalive
= self
.livestatus_broker
.livestatus
.handle_request(request
)
394 if self
.nagios_installed():
395 nagresponse
= self
.ask_nagios(request
)
396 print "nagresponse----------------------------------------------"
398 self
.assert_(self
.lines_equal(response
, nagresponse
))
400 # Again, but without filter
401 request
= """GET servicesbyhostgroup
402 Columns: hostgroup_name host_name service_description groups
405 ResponseHeader: fixed16
407 response
, keepalive
= self
.livestatus_broker
.livestatus
.handle_request(request
)
409 if self
.nagios_installed():
410 nagresponse
= self
.ask_nagios(request
)
411 print "nagresponse----------------------------------------------"
413 self
.assert_(self
.lines_equal(response
, nagresponse
))
416 def test_hostsbygroup(self
):
418 if self
.nagios_installed():
419 self
.start_nagios('1r_1h_1s')
422 for host
in self
.sched
.hosts
:
423 objlist
.append([host
, 0, 'UP'])
424 for service
in self
.sched
.services
:
425 objlist
.append([service
, 0, 'OK'])
426 self
.scheduler_loop(1, objlist
)
428 request
= """GET hostsbygroup
430 Columns: host_name hostgroup_name
431 Filter: groups >= allhosts
434 ResponseHeader: fixed16
437 response
, keepalive
= self
.livestatus_broker
.livestatus
.handle_request(request
)
439 if self
.nagios_installed():
440 nagresponse
= self
.ask_nagios(request
)
441 print "nagresponse----------------------------------------------"
443 self
.assert_(self
.lines_equal(response
, nagresponse
))
446 def test_status(self
):
448 if self
.nagios_installed():
449 self
.start_nagios('1r_1h_1s')
451 host
= self
.sched
.hosts
.find_by_name("test_host_0")
452 host
.checks_in_progress
= []
453 host
.act_depend_of
= [] # ignore the router
454 router
= self
.sched
.hosts
.find_by_name("test_router_0")
455 router
.checks_in_progress
= []
456 router
.act_depend_of
= [] # ignore the router
457 svc
= self
.sched
.services
.find_srv_by_name_and_hostname("test_host_0", "test_ok_0")
458 svc
.checks_in_progress
= []
459 svc
.act_depend_of
= [] # no hostchecks on critical checkresults
460 self
.scheduler_loop(2, [[host
, 0, 'UP'], [router
, 0, 'UP'], [svc
, 2, 'BAD']])
461 self
.update_broker(True)
462 #---------------------------------------------------------------
463 # get the full hosts table
464 #---------------------------------------------------------------
465 request
= 'GET hosts'
466 response
, keepalive
= self
.livestatus_broker
.livestatus
.handle_request(request
)
468 if self
.nagios_installed():
469 nagresponse
= self
.ask_nagios(request
)
470 print "nagresponse----------------------------------------------"
472 # todo 1 != 1.0000000000e+00
473 #self.assert_(self.lines_equal(response, nagresponse))
475 #---------------------------------------------------------------
476 # get only the host names and addresses
477 #---------------------------------------------------------------
478 request
= 'GET hosts\nColumns: name address groups\nColumnHeaders: on'
479 response
, keepalive
= self
.livestatus_broker
.livestatus
.handle_request(request
)
481 if self
.nagios_installed():
482 nagresponse
= self
.ask_nagios(request
)
483 print "nagresponse----------------------------------------------"
485 self
.assert_(self
.lines_equal(response
, nagresponse
))
487 #---------------------------------------------------------------
489 #---------------------------------------------------------------
490 request
= 'GET contacts'
491 response
, keepalive
= self
.livestatus_broker
.livestatus
.handle_request(request
)
492 print 'query_1_______________\n%s\n%s\n' % (request
, response
)
493 if self
.nagios_installed():
494 nagresponse
= self
.ask_nagios(request
)
495 print "nagresponse----------------------------------------------"
497 # There are some sick columns in the livestatus response like
498 # modified_attributes;modified_attributes_list
499 # These are not implemented in shinken-livestatus (never, i think)
500 #self.assert_(self.lines_equal(response, nagresponse))
502 #---------------------------------------------------------------
504 #---------------------------------------------------------------
505 request
= 'GET contacts\nColumns: name alias'
506 response
, keepalive
= self
.livestatus_broker
.livestatus
.handle_request(request
)
507 print 'query_2_______________\n%s\n%s\n' % (request
, response
)
508 if self
.nagios_installed():
509 nagresponse
= self
.ask_nagios(request
)
510 print "nagresponse----------------------------------------------"
512 self
.assert_(self
.lines_equal(response
, nagresponse
))
514 #---------------------------------------------------------------
516 #---------------------------------------------------------------
517 #self.scheduler_loop(3, svc, 2, 'BAD')
518 request
= 'GET services\nColumns: host_name description state\nFilter: state = 2\nColumnHeaders: on'
519 response
, keepalive
= self
.livestatus_broker
.livestatus
.handle_request(request
)
520 print 'query_3_______________\n%s\n%s\n' % (request
, response
)
521 self
.assert_(response
== 'host_name;description;state\ntest_host_0;test_ok_0;2\n')
522 request
= 'GET services\nColumns: host_name description state\nFilter: state = 2'
523 response
, keepalive
= self
.livestatus_broker
.livestatus
.handle_request(request
)
524 print 'query_3_______________\n%s\n%s\n' % (request
, response
)
525 self
.assert_(response
== 'test_host_0;test_ok_0;2\n')
526 request
= 'GET services\nColumns: host_name description state\nFilter: state = 0'
527 response
, keepalive
= self
.livestatus_broker
.livestatus
.handle_request(request
)
528 print 'query_3_______________\n%s\n%s\n' % (request
, response
)
529 self
.assert_(response
== '\n')
532 cmd
= "[%lu] SCHEDULE_SVC_DOWNTIME;test_host_0;test_ok_0;%d;%d;0;0;%d;lausser;blablub" % (now
, now
, now
+ duration
, duration
)
533 self
.sched
.run_external_command(cmd
)
534 self
.update_broker(True)
535 self
.scheduler_loop(1, [[svc
, 0, 'OK']])
536 self
.update_broker(True)
537 self
.scheduler_loop(3, [[svc
, 2, 'BAD']])
538 self
.update_broker(True)
539 request
= 'GET services\nColumns: host_name description scheduled_downtime_depth\nFilter: state = 2\nFilter: scheduled_downtime_depth = 1'
540 response
, keepalive
= self
.livestatus_broker
.livestatus
.handle_request(request
)
541 print 'query_3_______________\n%s\n%s\n' % (request
, response
)
542 self
.assert_(response
== 'test_host_0;test_ok_0;1\n')
544 #---------------------------------------------------------------
546 #---------------------------------------------------------------
547 request
= 'GET services\nColumns: host_name description state\nFilter: state = 2\nFilter: in_notification_period = 1\nAnd: 2\nFilter: state = 0\nOr: 2\nFilter: host_name = test_host_0\nFilter: description = test_ok_0\nAnd: 3\nFilter: contacts >= harri\nFilter: contacts >= test_contact\nOr: 3'
548 response
, keepalive
= self
.livestatus_broker
.livestatus
.handle_request(request
)
549 print 'query_4_______________\n%s\n%s\n' % (request
, response
)
550 self
.assert_(response
== 'test_host_0;test_ok_0;2\n')
552 #---------------------------------------------------------------
554 #---------------------------------------------------------------
555 request
= 'GET services\nStats: state = 0\nStats: state = 1\nStats: state = 2\nStats: state = 3'
556 response
, keepalive
= self
.livestatus_broker
.livestatus
.handle_request(request
)
557 print 'query_6_______________\n%s\n%s\n' % (request
, response
)
558 self
.assert_(response
== '0;0;1;0\n')
560 #---------------------------------------------------------------
562 #---------------------------------------------------------------
563 request
= 'GET services\nStats: state = 0\nStats: state = 1\nStats: state = 2\nStats: state = 3\nFilter: contacts >= test_contact'
564 response
, keepalive
= self
.livestatus_broker
.livestatus
.handle_request(request
)
565 print 'query_6_______________\n%s\n%s\n' % (request
, response
)
566 self
.assert_(response
== '0;0;1;0\n')
567 if self
.nagios_installed():
568 nagresponse
= self
.ask_nagios(request
)
569 print "nagresponse----------------------------------------------"
571 # TODO looks like a timing problem with nagios
572 #self.assert_(self.lines_equal(response, nagresponse))
577 print "got initial broks"
579 host
= self
.sched
.hosts
.find_by_name("test_host_0")
580 host
.checks_in_progress
= []
581 host
.act_depend_of
= [] # ignore the router
582 router
= self
.sched
.hosts
.find_by_name("test_router_0")
583 router
.checks_in_progress
= []
584 router
.act_depend_of
= [] # ignore the router
585 svc
= self
.sched
.services
.find_srv_by_name_and_hostname("test_host_0", "test_ok_0")
586 svc
.checks_in_progress
= []
587 svc
.act_depend_of
= [] # no hostchecks on critical checkresults
588 self
.scheduler_loop(2, [[host
, 0, 'UP'], [router
, 0, 'UP'], [svc
, 2, 'BAD']])
590 request
= 'GET services\nColumns: host_name description state\nOutputFormat: json'
591 response
, keepalive
= self
.livestatus_broker
.livestatus
.handle_request(request
)
592 print 'json wo headers__________\n%s\n%s\n' % (request
, response
)
593 self
.assert_(response
== '[["test_host_0","test_ok_0",2]]\n')
594 request
= 'GET services\nColumns: host_name description state\nOutputFormat: json\nColumnHeaders: on'
595 response
, keepalive
= self
.livestatus_broker
.livestatus
.handle_request(request
)
596 print 'json with headers__________\n%s\n%s\n' % (request
, response
)
597 self
.assert_(response
== '[["host_name","description","state"],["test_host_0","test_ok_0",2]]\n')
598 #100% mklivesttaus: self.assert_(response == '[["host_name","description","state"],\n["test_host_0","test_ok_0",2]]\n')
601 def test_thruk(self
):
603 if self
.nagios_installed():
604 self
.start_nagios('1r_1h_1s')
606 host
= self
.sched
.hosts
.find_by_name("test_host_0")
607 host
.checks_in_progress
= []
608 host
.act_depend_of
= [] # ignore the router
609 router
= self
.sched
.hosts
.find_by_name("test_router_0")
610 router
.checks_in_progress
= []
611 router
.act_depend_of
= [] # ignore the router
612 svc
= self
.sched
.services
.find_srv_by_name_and_hostname("test_host_0", "test_ok_0")
613 svc
.checks_in_progress
= []
614 svc
.act_depend_of
= [] # no hostchecks on critical checkresults
615 self
.scheduler_loop(2, [[host
, 0, 'UP'], [router
, 0, 'UP'], [svc
, 2, 'BAD']])
617 #---------------------------------------------------------------
618 # get the full hosts table
619 #---------------------------------------------------------------
620 request
= 'GET status\nColumns: livestatus_version program_version accept_passive_host_checks accept_passive_service_checks check_external_commands check_host_freshness check_service_freshness enable_event_handlers enable_flap_detection enable_notifications execute_host_checks execute_service_checks last_command_check last_log_rotation nagios_pid obsess_over_hosts obsess_over_services process_performance_data program_start interval_length'
621 response
, keepalive
= self
.livestatus_broker
.livestatus
.handle_request(request
)
624 request
= """GET hosts
626 Stats: check_type = 0
627 Stats: check_type = 1
628 Stats: has_been_checked = 1
631 Stats: has_been_checked = 1
634 Stats: has_been_checked = 1
637 Stats: has_been_checked = 0
638 Stats: has_been_checked = 0
639 Stats: active_checks_enabled = 0
641 Stats: has_been_checked = 0
642 Stats: scheduled_downtime_depth > 0
645 Stats: has_been_checked = 1
646 Stats: active_checks_enabled = 0
649 Stats: has_been_checked = 1
650 Stats: scheduled_downtime_depth > 0
653 Stats: has_been_checked = 1
654 Stats: acknowledged = 1
657 Stats: scheduled_downtime_depth > 0
658 Stats: has_been_checked = 1
661 Stats: active_checks_enabled = 0
662 Stats: has_been_checked = 1
665 Stats: active_checks_enabled = 1
666 Stats: acknowledged = 0
667 Stats: scheduled_downtime_depth = 0
668 Stats: has_been_checked = 1
671 Stats: acknowledged = 1
672 Stats: has_been_checked = 1
675 Stats: scheduled_downtime_depth > 0
676 Stats: has_been_checked = 1
679 Stats: active_checks_enabled = 0
682 Stats: active_checks_enabled = 1
683 Stats: acknowledged = 0
684 Stats: scheduled_downtime_depth = 0
685 Stats: has_been_checked = 1
687 Stats: is_flapping = 1
688 Stats: flap_detection_enabled = 0
689 Stats: notifications_enabled = 0
690 Stats: event_handler_enabled = 0
691 Stats: active_checks_enabled = 0
692 Stats: accept_passive_checks = 0
696 Separators: 10 59 44 124
697 ResponseHeader: fixed16"""
698 response
, keepalive
= self
.livestatus_broker
.livestatus
.handle_request(request
)
700 if self
.nagios_installed():
701 nagresponse
= self
.ask_nagios(request
)
702 print "nagresponse----------------------------------------------"
704 # TODO timing problem?
705 #self.assert_(self.lines_equal(response, nagresponse))
707 request
= """GET comments
708 Columns: host_name source type author comment entry_time entry_type expire_time
709 Filter: service_description ="""
710 response
, keepalive
= self
.livestatus_broker
.livestatus
.handle_request(request
)
712 if self
.nagios_installed():
713 nagresponse
= self
.ask_nagios(request
)
714 print "nagresponse----------------------------------------------"
716 self
.assert_(self
.lines_equal(response
, nagresponse
))
718 request
= """GET hosts
719 Columns: comments has_been_checked state name address acknowledged notifications_enabled active_checks_enabled is_flapping scheduled_downtime_depth is_executing notes_url_expanded action_url_expanded icon_image_expanded icon_image_alt last_check last_state_change plugin_output next_check long_plugin_output
720 Separators: 10 59 44 124
721 ResponseHeader: fixed16"""
722 response
, keepalive
= self
.livestatus_broker
.livestatus
.handle_request(request
)
727 cmd
= "[%lu] SCHEDULE_SVC_DOWNTIME;test_host_0;test_warning_00;%d;%d;0;0;%d;lausser;blablubsvc" % (now
, now
, now
+ duration
, duration
)
729 self
.sched
.run_external_command(cmd
)
730 if self
.nagios_installed():
731 self
.nagios_extcmd(cmd
)
732 cmd
= "[%lu] SCHEDULE_HOST_DOWNTIME;test_host_0;%d;%d;0;0;%d;lausser;blablubhost" % (now
, now
, now
+ duration
, duration
)
734 self
.sched
.run_external_command(cmd
)
735 if self
.nagios_installed():
736 self
.nagios_extcmd(cmd
)
738 self
.scheduler_loop(1, [[svc
, 0, 'OK']])
740 self
.scheduler_loop(3, [[svc
, 2, 'BAD']])
742 request
= """GET downtimes
743 Filter: service_description =
744 Columns: author comment end_time entry_time fixed host_name id start_time
745 Separators: 10 59 44 124
746 ResponseHeader: fixed16"""
747 response
, keepalive
= self
.livestatus_broker
.livestatus
.handle_request(request
)
749 if self
.nagios_installed():
751 nagresponse
= self
.ask_nagios(request
)
752 print "nagresponse----------------------------------------------"
754 #TODO the entry_times are different. find a way to round the numbers
755 # so that they are equal
756 #self.assert_(self.lines_equal(response, nagresponse))
758 request
= """GET comments
759 Filter: service_description =
760 Columns: author comment
761 Separators: 10 59 44 124
762 ResponseHeader: fixed16"""
763 response
, keepalive
= self
.livestatus_broker
.livestatus
.handle_request(request
)
765 if self
.nagios_installed():
767 nagresponse
= self
.ask_nagios(request
)
768 print "nagresponse----------------------------------------------"
770 #self.assert_(self.lines_equal(response, nagresponse))
772 request
= """GET services
773 Filter: has_been_checked = 1
774 Filter: check_type = 0
775 Stats: sum has_been_checked
777 Separators: 10 59 44 124
778 ResponseHeader: fixed16"""
779 response
, keepalive
= self
.livestatus_broker
.livestatus
.handle_request(request
)
782 request
= """GET services
783 Filter: has_been_checked = 1
784 Filter: check_type = 0
785 Stats: sum has_been_checked
787 Stats: sum execution_time
789 Stats: min execution_time
791 Stats: max execution_time
792 Separators: 10 59 44 124
793 ResponseHeader: fixed16"""
794 response
, keepalive
= self
.livestatus_broker
.livestatus
.handle_request(request
)
797 request
= """GET services\nFilter: has_been_checked = 1\nFilter: check_type = 0\nStats: sum has_been_checked as has_been_checked\nStats: sum latency as latency_sum\nStats: sum execution_time as execution_time_sum\nStats: min latency as latency_min\nStats: min execution_time as execution_time_min\nStats: max latency as latency_max\nStats: max execution_time as execution_time_max\n\nResponseHeader: fixed16"""
798 response
, keepalive
= self
.livestatus_broker
.livestatus
.handle_request(request
)
801 request
= """GET hostgroups\nColumnHeaders: on\nResponseHeader: fixed16"""
802 response
, keepalive
= self
.livestatus_broker
.livestatus
.handle_request(request
)
804 if self
.nagios_installed():
805 nagresponse
= self
.ask_nagios(request
)
806 print "nagresponse----------------------------------------------"
808 # TODO members_with_state
809 #self.assert_(self.lines_equal(response, nagresponse))
811 request
= """GET hosts\nColumns: name groups\nColumnHeaders: on\nResponseHeader: fixed16"""
812 response
, keepalive
= self
.livestatus_broker
.livestatus
.handle_request(request
)
814 if self
.nagios_installed():
815 nagresponse
= self
.ask_nagios(request
)
816 print "nagresponse----------------------------------------------"
818 self
.assert_(self
.lines_equal(response
, nagresponse
))
820 request
= """GET hostgroups\nColumns: name num_services num_services_ok\nColumnHeaders: on\nResponseHeader: fixed16"""
821 response
, keepalive
= self
.livestatus_broker
.livestatus
.handle_request(request
)
823 if self
.nagios_installed():
824 nagresponse
= self
.ask_nagios(request
)
825 print "nagresponse----------------------------------------------"
827 self
.assert_(self
.lines_equal(response
, nagresponse
))
829 request
= """GET hostgroups\nColumns: name num_services_pending num_services_ok num_services_warn num_services_crit num_services_unknown worst_service_state worst_service_hard_state\nColumnHeaders: on\nResponseHeader: fixed16"""
830 response
, keepalive
= self
.livestatus_broker
.livestatus
.handle_request(request
)
833 self
.scheduler_loop(1, [[host
, 0, 'UP'], [router
, 0, 'UP'], [svc
, 0, 'OK']])
835 self
.scheduler_loop(1, [[host
, 0, 'UP'], [router
, 0, 'UP'], [svc
, 1, 'WARNING']])
838 print "WARNING SOFT;1"
839 # worst_service_state 1, worst_service_hard_state 0
840 request
= """GET hostgroups\nColumns: name num_services_pending num_services_ok num_services_warn num_services_crit num_services_unknown worst_service_state worst_service_hard_state\nColumnHeaders: on\nResponseHeader: fixed16"""
841 response
, keepalive
= self
.livestatus_broker
.livestatus
.handle_request(request
)
843 self
.scheduler_loop(3, [[host
, 0, 'UP'], [router
, 0, 'UP'], [svc
, 1, 'WARNING']])
845 print "WARNING HARD;3"
846 # worst_service_state 1, worst_service_hard_state 1
847 request
= """GET hostgroups\nColumns: name num_services_pending num_services_ok num_services_warn num_services_crit num_services_unknown worst_service_state worst_service_hard_state\nColumnHeaders: on\nResponseHeader: fixed16"""
848 response
, keepalive
= self
.livestatus_broker
.livestatus
.handle_request(request
)
850 for s
in self
.livestatus_broker
.livestatus
.services
.values():
851 print "%s %d %s;%d" % (s
.state
, s
.state_id
, s
.state_type
, s
.attempt
)
854 def test_thruk_comments(self
):
856 host
= self
.sched
.hosts
.find_by_name("test_host_0")
857 host
.checks_in_progress
= []
858 host
.act_depend_of
= [] # ignore the router
859 router
= self
.sched
.hosts
.find_by_name("test_router_0")
860 router
.checks_in_progress
= []
861 router
.act_depend_of
= [] # ignore the router
862 svc
= self
.sched
.services
.find_srv_by_name_and_hostname("test_host_0", "test_ok_0")
863 svc
.checks_in_progress
= []
864 svc
.act_depend_of
= [] # no hostchecks on critical checkresults
867 # downtime valid for the next 2 minutes
868 cmd
= "[%lu] SCHEDULE_SVC_DOWNTIME;test_host_0;test_ok_0;%d;%d;1;0;%d;lausser;blablub" % (now
, now
, now
+ duration
, duration
)
869 self
.sched
.run_external_command(cmd
)
870 svc
= self
.sched
.services
.find_srv_by_name_and_hostname("test_host_0", "test_ok_0")
871 svc
.checks_in_progress
= []
872 svc
.act_depend_of
= [] # no hostchecks on critical checkresults
873 self
.scheduler_loop(1, [[host
, 0, 'UP'], [router
, 0, 'UP'], [svc
, 0, 'OK']], do_sleep
=False)
875 print "downtime was scheduled. check its activity and the comment"
876 self
.assert_(len(self
.sched
.downtimes
) == 1)
877 self
.assert_(len(svc
.downtimes
) == 1)
878 self
.assert_(svc
.downtimes
[0] in self
.sched
.downtimes
.values())
879 self
.assert_(svc
.downtimes
[0].fixed
)
880 self
.assert_(svc
.downtimes
[0].is_in_effect
)
881 self
.assert_(not svc
.downtimes
[0].can_be_deleted
)
882 self
.assert_(len(self
.sched
.comments
) == 1)
883 self
.assert_(len(svc
.comments
) == 1)
884 self
.assert_(svc
.comments
[0] in self
.sched
.comments
.values())
885 self
.assert_(svc
.downtimes
[0].comment_id
== svc
.comments
[0].id)
888 cmd
= "[%lu] ADD_SVC_COMMENT;test_host_0;test_ok_0;1;lausser;comment" % now
889 self
.sched
.run_external_command(cmd
)
890 #cmd = "[%lu] ADD_HOST_COMMENT;test_host_0;1;lausser;hcomment" % now
891 #self.sched.run_external_command(cmd)
892 self
.scheduler_loop(1, [[host
, 0, 'UP'], [router
, 0, 'UP'], [svc
, 0, 'OK']], do_sleep
=False)
893 self
.assert_(len(self
.sched
.comments
) == 2)
894 self
.assert_(len(svc
.comments
) == 2)
897 svc_comment_list
= (',').join([str(c
.id) for c
in svc
.comments
])
899 #request = """GET comments\nColumns: host_name service_description id source type author comment entry_time entry_type persistent expire_time expires\nFilter: service_description !=\nResponseHeader: fixed16\nOutputFormat: json\n"""
900 request
= """GET services\nColumns: comments host_comments host_is_executing is_executing\nFilter: service_description !=\nResponseHeader: fixed16\nOutputFormat: json\n"""
901 response
, _
= self
.livestatus_broker
.livestatus
.handle_request(request
)
903 good_response
= """200 17
904 [[[""" + svc_comment_list
+"""],[],0,0]]
906 self
.assert_(response
== good_response
) # json
908 request
= """GET services\nColumns: comments host_comments host_is_executing is_executing\nFilter: service_description !=\nResponseHeader: fixed16\n"""
909 response
, _
= self
.livestatus_broker
.livestatus
.handle_request(request
)
911 good_response
= """200 9
912 """ + svc_comment_list
+ """;;0;0
914 self
.assert_(response
== good_response
) # csv
916 request
= """GET comments\n\
917 Columns: author entry_type expires expire_time host_name id persistent service_description source type\n\
918 Filter: service_description !=\n\
919 Filter: service_description =\n\
921 OutputFormat: json\n\
922 ResponseHeader: fixed16\n"""
923 response
, _
= self
.livestatus_broker
.livestatus
.handle_request(request
)
924 good_response
= """200 115
925 [["(Nagios Process)",2,0,0,"test_host_0",1,0,"test_ok_0",0,2],["lausser",1,0,0,"test_host_0",2,1,"test_ok_0",1,2]]
927 self
.assert_(response
== good_response
)
930 def test_thruk_logs(self
):
933 host
= self
.sched
.hosts
.find_by_name("test_host_0")
934 host
.checks_in_progress
= []
935 host
.act_depend_of
= [] # ignore the router
936 router
= self
.sched
.hosts
.find_by_name("test_router_0")
937 router
.checks_in_progress
= []
938 router
.act_depend_of
= [] # ignore the router
939 svc
= self
.sched
.services
.find_srv_by_name_and_hostname("test_host_0", "test_ok_0")
940 svc
.checks_in_progress
= []
941 svc
.act_depend_of
= [] # no hostchecks on critical checkresults
942 self
.scheduler_loop(3, [[host
, 0, 'UP'], [router
, 0, 'UP'], [svc
, 1, 'WARNING']])
946 # downtime valid for the next 2 minutes
947 cmd
= "[%lu] SCHEDULE_SVC_DOWNTIME;test_host_0;test_ok_0;%d;%d;1;0;%d;lausser;blablub" % (now
, now
, now
+ duration
, duration
)
948 self
.sched
.run_external_command(cmd
)
949 svc
= self
.sched
.services
.find_srv_by_name_and_hostname("test_host_0", "test_ok_0")
950 svc
.checks_in_progress
= []
951 svc
.act_depend_of
= [] # no hostchecks on critical checkresults
952 self
.scheduler_loop(1, [[host
, 0, 'UP'], [router
, 0, 'UP'], [svc
, 0, 'OK']], do_sleep
=False)
954 cmd
= "[%lu] ADD_SVC_COMMENT;test_host_0;test_ok_0;1;lausser;comment" % now
955 self
.sched
.run_external_command(cmd
)
957 self
.scheduler_loop(1, [[host
, 0, 'UP'], [router
, 0, 'UP'], [svc
, 0, 'OK']], do_sleep
=False)
960 self
.scheduler_loop(3, [[host
, 2, 'DOWN'], [router
, 0, 'UP'], [svc
, 0, 'OK']], do_sleep
=False)
963 self
.scheduler_loop(3, [[host
, 0, 'UP'], [router
, 0, 'UP'], [svc
, 0, 'OK']], do_sleep
=False)
967 # show history for service
969 Columns: time type options state
970 Filter: time >= """ + str(int(start
)) + """
971 Filter: time <= """ + str(int(end
)) + """
972 Filter: type = SERVICE ALERT
973 Filter: type = HOST ALERT
974 Filter: type = SERVICE FLAPPING ALERT
975 Filter: type = HOST FLAPPING ALERT
976 Filter: type = SERVICE DOWNTIME ALERT
977 Filter: type = HOST DOWNTIME ALERT
979 Filter: host_name = test_host_0
980 Filter: service_description = test_ok_0
982 Filter: type ~ starting...
983 Filter: type ~ shutting down...
985 Filter: current_service_description !=
987 Filter: service_description =
990 Filter: service_description =
995 response
, keepalive
= self
.livestatus_broker
.livestatus
.handle_request(request
)
997 self
.assert_(self
.contains_line(response
, 'SERVICE DOWNTIME ALERT;test_host_0;test_ok_0;STARTED; Service has entered a period of scheduled downtime'))
1000 def test_thruk_logs_alerts_summary(self
):
1003 host
= self
.sched
.hosts
.find_by_name("test_host_0")
1004 host
.checks_in_progress
= []
1005 host
.act_depend_of
= [] # ignore the router
1006 router
= self
.sched
.hosts
.find_by_name("test_router_0")
1007 router
.checks_in_progress
= []
1008 router
.act_depend_of
= [] # ignore the router
1009 svc
= self
.sched
.services
.find_srv_by_name_and_hostname("test_host_0", "test_ok_0")
1010 svc
.checks_in_progress
= []
1011 svc
.act_depend_of
= [] # no hostchecks on critical checkresults
1012 self
.scheduler_loop(3, [[host
, 0, 'UP'], [router
, 0, 'UP'], [svc
, 1, 'WARNING']])
1013 self
.update_broker()
1016 # downtime valid for the next 2 minutes
1017 cmd
= "[%lu] SCHEDULE_SVC_DOWNTIME;test_host_0;test_ok_0;%d;%d;1;0;%d;lausser;blablub" % (now
, now
, now
+ duration
, duration
)
1018 self
.sched
.run_external_command(cmd
)
1019 svc
= self
.sched
.services
.find_srv_by_name_and_hostname("test_host_0", "test_ok_0")
1020 svc
.checks_in_progress
= []
1021 svc
.act_depend_of
= [] # no hostchecks on critical checkresults
1022 self
.scheduler_loop(1, [[host
, 0, 'UP'], [router
, 0, 'UP'], [svc
, 0, 'OK']], do_sleep
=False)
1024 cmd
= "[%lu] ADD_SVC_COMMENT;test_host_0;test_ok_0;1;lausser;comment" % now
1025 self
.sched
.run_external_command(cmd
)
1027 self
.scheduler_loop(1, [[host
, 0, 'UP'], [router
, 0, 'UP'], [svc
, 0, 'OK']], do_sleep
=False)
1028 self
.update_broker()
1030 self
.scheduler_loop(3, [[host
, 2, 'DOWN'], [router
, 0, 'UP'], [svc
, 0, 'OK']], do_sleep
=False)
1031 self
.update_broker()
1033 self
.scheduler_loop(3, [[host
, 0, 'UP'], [router
, 0, 'UP'], [svc
, 0, 'OK']], do_sleep
=False)
1034 self
.update_broker()
1037 # is this an error in thruk?
1039 request
= """GET log
1040 Filter: options ~ ;HARD;
1041 Filter: type = HOST ALERT
1042 Filter: time >= 1284056080
1043 Filter: time <= 1284660880
1044 Filter: current_service_description !=
1045 Filter: service_description =
1046 Filter: host_name !=
1048 Filter: service_description =
1052 Columns: time state state_type host_name service_description current_host_groups current_service_groups plugin_output"""
1054 response
, keepalive
= self
.livestatus_broker
.livestatus
.handle_request(request
)
1058 def test_thruk_logs_current(self
):
1061 host
= self
.sched
.hosts
.find_by_name("test_host_0")
1062 host
.checks_in_progress
= []
1063 host
.act_depend_of
= [] # ignore the router
1064 router
= self
.sched
.hosts
.find_by_name("test_router_0")
1065 router
.checks_in_progress
= []
1066 router
.act_depend_of
= [] # ignore the router
1067 svc
= self
.sched
.services
.find_srv_by_name_and_hostname("test_host_0", "test_ok_0")
1068 svc
.checks_in_progress
= []
1069 svc
.act_depend_of
= [] # no hostchecks on critical checkresults
1070 self
.scheduler_loop(3, [[host
, 0, 'UP'], [router
, 0, 'UP'], [svc
, 1, 'WARNING']])
1071 self
.update_broker()
1074 # downtime valid for the next 2 minutes
1075 cmd
= "[%lu] SCHEDULE_SVC_DOWNTIME;test_host_0;test_ok_0;%d;%d;1;0;%d;lausser;blablub" % (now
, now
, now
+ duration
, duration
)
1076 self
.sched
.run_external_command(cmd
)
1077 svc
= self
.sched
.services
.find_srv_by_name_and_hostname("test_host_0", "test_ok_0")
1078 svc
.checks_in_progress
= []
1079 svc
.act_depend_of
= [] # no hostchecks on critical checkresults
1080 self
.scheduler_loop(1, [[host
, 0, 'UP'], [router
, 0, 'UP'], [svc
, 0, 'OK']], do_sleep
=False)
1082 cmd
= "[%lu] ADD_SVC_COMMENT;test_host_0;test_ok_0;1;lausser;comment" % now
1083 self
.sched
.run_external_command(cmd
)
1085 self
.scheduler_loop(1, [[host
, 0, 'UP'], [router
, 0, 'UP'], [svc
, 0, 'OK']], do_sleep
=False)
1086 self
.update_broker()
1088 self
.scheduler_loop(3, [[host
, 2, 'DOWN'], [router
, 0, 'UP'], [svc
, 0, 'OK']], do_sleep
=False)
1089 self
.update_broker()
1091 self
.scheduler_loop(3, [[host
, 0, 'UUP'], [router
, 0, 'UP'], [svc
, 0, 'OK']], do_sleep
=False)
1092 self
.update_broker()
1094 # self.scheduler_loop(3, [[host, 0, 'UP'], [router, 2, 'DOWN'], [svc, 0, 'OK']], do_sleep=False)
1095 # self.update_broker()
1098 # show history for service
1099 request
= """GET log
1100 Columns: time type options state current_host_name
1101 Filter: time >= """ + str(int(start
)) + """
1102 Filter: time <= """ + str(int(end
)) + """
1103 Filter: type = SERVICE ALERT
1104 Filter: type = HOST ALERT
1105 Filter: type = SERVICE FLAPPING ALERT
1106 Filter: type = HOST FLAPPING ALERT
1107 Filter: type = SERVICE DOWNTIME ALERT
1108 Filter: type = HOST DOWNTIME ALERT
1110 Filter: current_host_name = test_host_0
1111 Filter: current_service_description = test_ok_0
1113 request
= """GET log
1114 Columns: time type options state current_host_name
1115 Filter: time >= """ + str(int(start
)) + """
1116 Filter: time <= """ + str(int(end
)) + """
1117 Filter: current_host_name = test_host_0
1118 Filter: current_service_description = test_ok_0
1121 response
, keepalive
= self
.livestatus_broker
.livestatus
.handle_request(request
)
1125 def test_thruk_tac_svc(self
):
1127 if self
.nagios_installed():
1128 self
.start_nagios('1r_1h_1s')
1129 self
.update_broker()
1132 host
= self
.sched
.hosts
.find_by_name("test_host_0")
1133 host
.checks_in_progress
= []
1134 host
.act_depend_of
= [] # ignore the router
1135 router
= self
.sched
.hosts
.find_by_name("test_router_0")
1136 router
.checks_in_progress
= []
1137 router
.act_depend_of
= [] # ignore the router
1138 svc
= self
.sched
.services
.find_srv_by_name_and_hostname("test_host_0", "test_ok_0")
1139 svc
.checks_in_progress
= []
1140 svc
.act_depend_of
= [] # no hostchecks on critical checkresults
1141 self
.scheduler_loop(3, [[host
, 0, 'UP'], [router
, 0, 'UP'], [svc
, 1, 'WARNING']])
1142 self
.update_broker()
1145 # downtime valid for the next 2 minutes
1146 cmd
= "[%lu] SCHEDULE_SVC_DOWNTIME;test_host_0;test_ok_0;%d;%d;1;0;%d;lausser;blablub" % (now
, now
, now
+ duration
, duration
)
1147 self
.sched
.run_external_command(cmd
)
1148 svc
= self
.sched
.services
.find_srv_by_name_and_hostname("test_host_0", "test_ok_0")
1149 svc
.checks_in_progress
= []
1150 svc
.act_depend_of
= [] # no hostchecks on critical checkresults
1151 self
.scheduler_loop(1, [[host
, 0, 'UP'], [router
, 0, 'UP'], [svc
, 0, 'OK']], do_sleep
=False)
1153 cmd
= "[%lu] ADD_SVC_COMMENT;test_host_0;test_ok_0;1;lausser;comment" % now
1154 self
.sched
.run_external_command(cmd
)
1156 self
.scheduler_loop(1, [[host
, 0, 'UP'], [router
, 0, 'UP'], [svc
, 0, 'OK']], do_sleep
=False)
1157 self
.update_broker()
1159 self
.scheduler_loop(3, [[host
, 2, 'DOWN'], [router
, 0, 'UP'], [svc
, 0, 'OK']], do_sleep
=False)
1160 self
.update_broker()
1162 self
.scheduler_loop(3, [[host
, 0, 'UUP'], [router
, 0, 'UP'], [svc
, 0, 'OK']], do_sleep
=False)
1163 self
.update_broker()
1165 # self.scheduler_loop(3, [[host, 0, 'UP'], [router, 2, 'DOWN'], [svc, 0, 'OK']], do_sleep=False)
1166 # self.update_broker()
1169 # show history for service
1170 request
= """GET services
1171 Filter: has_been_checked = 1
1172 Filter: check_type = 0
1173 Stats: sum has_been_checked
1175 Stats: sum execution_time
1177 Stats: min execution_time
1179 Stats: max execution_time"""
1181 response
, keepalive
= self
.livestatus_broker
.livestatus
.handle_request(request
)
1183 # nagios comparison makes no sense, because the latencies/execution times will surely differ
1184 if self
.nagios_installed():
1185 nagresponse
= self
.ask_nagios(request
)
1187 # self.assert_(self.lines_equal(response, nagresponse))
1190 def test_columns(self
):
1192 self
.update_broker()
1193 #---------------------------------------------------------------
1194 # get the columns meta-table
1195 #---------------------------------------------------------------
1196 request
= """GET columns"""
1197 response
, keepalive
= self
.livestatus_broker
.livestatus
.handle_request(request
)
1201 def test_scheduler_table(self
):
1203 self
.update_broker()
1205 creation_tab
= {'scheduler_name' : 'scheduler-1', 'address' : 'localhost', 'spare' : '0'}
1206 schedlink
= SchedulerLink(creation_tab
)
1207 schedlink
.pythonize()
1208 schedlink
.alive
= True
1209 b
= schedlink
.get_initial_status_brok()
1211 creation_tab
= {'scheduler_name' : 'scheduler-2', 'address' : 'othernode', 'spare' : '1'}
1212 schedlink
= SchedulerLink(creation_tab
)
1213 schedlink
.pythonize()
1214 schedlink
.alive
= True
1215 b2
= schedlink
.get_initial_status_brok()
1218 self
.update_broker()
1219 #---------------------------------------------------------------
1220 # get the columns meta-table
1221 #---------------------------------------------------------------
1222 request
= """GET schedulers"""
1223 response
, keepalive
= self
.livestatus_broker
.livestatus
.handle_request(request
)
1225 good_response
= """address;alive;name;port;spare;weight
1226 othernode;1;scheduler-2;7768;1;1
1227 localhost;1;scheduler-1;7768;0;1
1229 print response
, 'FUCK'
1230 print "FUCK", response
, "TOTO"
1231 self
.assert_(self
.lines_equal(response
, good_response
))
1233 #Now we update a scheduler state and we check
1235 schedlink
.alive
= False
1236 b
= schedlink
.get_update_status_brok()
1238 self
.update_broker()
1239 request
= """GET schedulers"""
1240 response
, keepalive
= self
.livestatus_broker
.livestatus
.handle_request(request
)
1241 good_response
= """address;alive;name;port;spare;weight
1242 othernode;0;scheduler-2;7768;1;1
1243 localhost;1;scheduler-1;7768;0;1
1245 self
.assert_(self
.lines_equal(response
, good_response
))
1249 def test_reactionner_table(self
):
1251 self
.update_broker()
1252 creation_tab
= {'reactionner_name' : 'reactionner-1', 'address' : 'localhost', 'spare' : '0'}
1253 reac
= ReactionnerLink(creation_tab
)
1256 b
= reac
.get_initial_status_brok()
1258 creation_tab
= {'reactionner_name' : 'reactionner-2', 'address' : 'othernode', 'spare' : '1'}
1259 reac
= ReactionnerLink(creation_tab
)
1262 b2
= reac
.get_initial_status_brok()
1265 self
.update_broker()
1266 #---------------------------------------------------------------
1267 # get the columns meta-table
1268 #---------------------------------------------------------------
1269 request
= """GET reactionners"""
1270 response
, keepalive
= self
.livestatus_broker
.livestatus
.handle_request(request
)
1272 good_response
= """address;alive;name;port;spare
1273 localhost;1;reactionner-1;7769;0
1274 othernode;1;reactionner-2;7769;1
1276 print response
== good_response
1277 self
.assert_(self
.lines_equal(response
, good_response
))
1279 #Now the update part
1281 b2
= reac
.get_update_status_brok()
1283 self
.update_broker()
1284 request
= """GET reactionners"""
1285 response
, keepalive
= self
.livestatus_broker
.livestatus
.handle_request(request
)
1287 good_response
= """address;alive;name;port;spare
1288 localhost;1;reactionner-1;7769;0
1289 othernode;0;reactionner-2;7769;1
1291 print response
== good_response
1292 self
.assert_(self
.lines_equal(response
, good_response
))
1296 def test_poller_table(self
):
1298 self
.update_broker()
1300 creation_tab
= {'poller_name' : 'poller-1', 'address' : 'localhost', 'spare' : '0'}
1301 pol
= PollerLink(creation_tab
)
1304 b
= pol
.get_initial_status_brok()
1306 creation_tab
= {'poller_name' : 'poller-2', 'address' : 'othernode', 'spare' : '1'}
1307 pol
= PollerLink(creation_tab
)
1310 b2
= pol
.get_initial_status_brok()
1313 self
.update_broker()
1314 #---------------------------------------------------------------
1315 # get the columns meta-table
1316 #---------------------------------------------------------------
1317 request
= """GET pollers"""
1318 response
, keepalive
= self
.livestatus_broker
.livestatus
.handle_request(request
)
1320 good_response
= """address;alive;name;port;spare
1321 localhost;1;poller-1;7771;0
1322 othernode;1;poller-2;7771;1
1324 print response
== good_response
1325 self
.assert_(self
.lines_equal(response
, good_response
))
1327 #Now the update part
1329 b2
= pol
.get_update_status_brok()
1332 self
.update_broker()
1333 #---------------------------------------------------------------
1334 # get the columns meta-table
1335 #---------------------------------------------------------------
1336 request
= """GET pollers"""
1337 response
, keepalive
= self
.livestatus_broker
.livestatus
.handle_request(request
)
1339 good_response
= """address;alive;name;port;spare
1340 localhost;1;poller-1;7771;0
1341 othernode;0;poller-2;7771;1
1343 print response
== good_response
1344 self
.assert_(self
.lines_equal(response
, good_response
))
1348 def test_broker_table(self
):
1350 self
.update_broker()
1352 creation_tab
= {'broker_name' : 'broker-1', 'address' : 'localhost', 'spare' : '0'}
1353 pol
= BrokerLink(creation_tab
)
1356 b
= pol
.get_initial_status_brok()
1358 creation_tab
= {'broker_name' : 'broker-2', 'address' : 'othernode', 'spare' : '1'}
1359 pol
= BrokerLink(creation_tab
)
1362 b2
= pol
.get_initial_status_brok()
1365 self
.update_broker()
1366 #---------------------------------------------------------------
1367 # get the columns meta-table
1368 #---------------------------------------------------------------
1369 request
= """GET brokers"""
1370 response
, keepalive
= self
.livestatus_broker
.livestatus
.handle_request(request
)
1372 good_response
= """address;alive;name;port;spare
1373 localhost;1;broker-1;7772;0
1374 othernode;1;broker-2;7772;1
1376 print response
== good_response
1377 self
.assert_(self
.lines_equal(response
, good_response
))
1379 #Now the update part
1381 b2
= pol
.get_initial_status_brok()
1384 self
.update_broker()
1385 #---------------------------------------------------------------
1386 # get the columns meta-table
1387 #---------------------------------------------------------------
1388 request
= """GET brokers"""
1389 response
, keepalive
= self
.livestatus_broker
.livestatus
.handle_request(request
)
1391 good_response
= """address;alive;name;port;spare
1392 localhost;1;broker-1;7772;0
1393 othernode;0;broker-2;7772;1
1395 print response
== good_response
1396 self
.assert_(self
.lines_equal(response
, good_response
))
1400 def test_problems_table(self
):
1402 self
.update_broker()
1403 host
= self
.sched
.hosts
.find_by_name("test_host_0")
1404 host
.checks_in_progress
= []
1405 host
.act_depend_of
= [] # ignore the router
1406 router
= self
.sched
.hosts
.find_by_name("test_router_0")
1407 router
.checks_in_progress
= []
1408 router
.act_depend_of
= [] # ignore the router
1409 svc
= self
.sched
.services
.find_srv_by_name_and_hostname("test_host_0", "test_ok_0")
1410 svc
.checks_in_progress
= []
1411 svc
.act_depend_of
= [] # no hostchecks on critical checkresults
1412 self
.scheduler_loop(4, [[host
, 2, 'DOWN'], [router
, 2, 'DOWN'], [svc
, 2, 'BAD']])
1413 print "Is router a problem?", router
.is_problem
, router
.state
, router
.state_type
1414 print "Is host a problem?", host
.is_problem
, host
.state
, host
.state_type
1415 print "Is service a problem?", svc
.is_problem
, svc
.state
, svc
.state_type
1416 self
.update_broker()
1417 print "All", self
.livestatus_broker
.hosts
1418 for h
in self
.livestatus_broker
.hosts
.values():
1419 print h
.get_dbg_name(), h
.is_problem
1421 #---------------------------------------------------------------
1422 # get the columns meta-table
1423 #---------------------------------------------------------------
1424 request
= """GET problems"""
1425 response
, keepalive
= self
.livestatus_broker
.livestatus
.handle_request(request
)
1426 print "FUCK", response
1427 good_response
= """impacts;source
1428 test_host_0,test_host_0/test_ok_0;test_router_0
1430 print response
== good_response
1431 self
.assert_(response
== good_response
)
1434 def test_parent_childs_dep_lists(self
):
1436 self
.update_broker()
1437 host
= self
.sched
.hosts
.find_by_name("test_host_0")
1438 router
= self
.sched
.hosts
.find_by_name("test_router_0")
1439 svc
= self
.sched
.services
.find_srv_by_name_and_hostname("test_host_0", "test_ok_0")
1441 #---------------------------------------------------------------
1442 # get the columns meta-table
1443 #---------------------------------------------------------------
1444 # first test if test_router_0 is in the host parent list
1445 request
= 'GET hosts\nColumns: host_name parent_dependencies\nFilter: host_name = test_host_0\n'
1446 response
, keepalive
= self
.livestatus_broker
.livestatus
.handle_request(request
)
1447 good_response
= """test_host_0;test_router_0"""
1448 self
.assert_(response
.strip() == good_response
.strip())
1450 # Now check if host is in the child router list
1451 request
= 'GET hosts\nColumns: host_name child_dependencies\nFilter: host_name = test_router_0\n'
1452 response
, keepalive
= self
.livestatus_broker
.livestatus
.handle_request(request
)
1453 good_response
= """test_router_0;test_host_0"""
1454 self
.assert_(response
.strip() == good_response
.strip())
1456 # Now check with the service
1457 request
= 'GET hosts\nColumns: host_name child_dependencies\nFilter: host_name = test_host_0\n'
1458 response
, keepalive
= self
.livestatus_broker
.livestatus
.handle_request(request
)
1459 good_response
= """test_host_0;test_host_0/test_ok_0"""
1460 self
.assert_(response
.strip() == good_response
.strip())
1462 # And check the parent for the service
1463 request
= 'GET services\nColumns: parent_dependencies\nFilter: host_name = test_host_0\n'
1464 response
, keepalive
= self
.livestatus_broker
.livestatus
.handle_request(request
)
1465 good_response
= """test_host_0"""
1466 self
.assert_(response
.strip() == good_response
.strip())
1469 def test_limit(self
):
1471 if self
.nagios_installed():
1472 self
.start_nagios('1r_1h_1s')
1474 self
.update_broker()
1475 #---------------------------------------------------------------
1476 # get the full hosts table
1477 #---------------------------------------------------------------
1478 request
= 'GET hosts\nColumns: host_name\n'
1479 response
, keepalive
= self
.livestatus_broker
.livestatus
.handle_request(request
)
1481 good_response
= """test_host_0
1484 self
.assert_(self
.lines_equal(response
, good_response
))
1486 request
= 'GET hosts\nColumns: host_name\nLimit: 1\n'
1487 response
, keepalive
= self
.livestatus_broker
.livestatus
.handle_request(request
)
1489 good_response
= """test_host_0
1491 # it must be test_host_0 because with Limit: the output is
1492 # alphabetically ordered
1493 self
.assert_(response
== good_response
)
1494 # TODO look whats wrong
1495 if self
.nagios_installed():
1496 nagresponse
= self
.ask_nagios(request
)
1498 # self.assert_(self.lines_equal(response, nagresponse))
1502 def test_problem_impact_in_host_service(self
):
1505 self
.update_broker()
1507 host_router_0
= self
.sched
.hosts
.find_by_name("test_router_0")
1508 host_router_0
.checks_in_progress
= []
1510 #Then initialize host under theses routers
1511 host_0
= self
.sched
.hosts
.find_by_name("test_host_0")
1512 host_0
.checks_in_progress
= []
1514 all_hosts
= [host_router_0
, host_0
]
1515 all_routers
= [host_router_0
]
1516 all_servers
= [host_0
]
1518 print "- 4 x UP -------------------------------------"
1519 self
.scheduler_loop(1, [[host_router_0
, 0, 'UP'], [host_0
, 0, 'UP']], do_sleep
=False)
1520 self
.scheduler_loop(1, [[host_router_0
, 1, 'DOWN']], do_sleep
=False)
1521 self
.scheduler_loop(1, [[host_router_0
, 1, 'DOWN']], do_sleep
=False)
1522 self
.scheduler_loop(1, [[host_router_0
, 1, 'DOWN']], do_sleep
=False)
1523 self
.scheduler_loop(1, [[host_router_0
, 1, 'DOWN']], do_sleep
=False)
1524 self
.scheduler_loop(1, [[host_router_0
, 1, 'DOWN']], do_sleep
=False)
1526 #Max attempt is reach, should be HARD now
1527 for h
in all_routers
:
1528 self
.assert_(h
.state
== 'DOWN')
1529 self
.assert_(h
.state_type
== 'HARD')
1531 for b
in self
.sched
.broks
.values():
1532 print "All broks", b
.type, b
1533 if b
.type == 'update_host_status':
1535 print "Impacts", b
.data
['impacts']
1536 print "Sources", b
.data
['source_problems']
1538 for b
in host_router_0
.broks
:
1539 print " host_router_0.broks", b
1541 self
.update_broker()
1543 print "source de host_0", host_0
.source_problems
1544 for i
in host_0
.source_problems
:
1545 print "source", i
.get_name()
1546 print "impacts de host_router_0", host_router_0
.impacts
1547 for i
in host_router_0
.impacts
:
1548 print "impact", i
.get_name()
1550 #---------------------------------------------------------------
1551 # get the full hosts table
1552 #---------------------------------------------------------------
1553 print "Got source problems"
1554 request
= 'GET hosts\nColumns: host_name is_impact source_problems\n'
1555 response
, keepalive
= self
.livestatus_broker
.livestatus
.handle_request(request
)
1556 print "moncullulu2", response
1557 good_response
= """test_router_0;0;
1558 test_host_0;1;test_router_0
1560 #self.assert_(self.lines_equal(response, good_response))
1562 print "Now got impact"
1563 request
= 'GET hosts\nColumns: host_name is_problem impacts\n'
1564 response
, keepalive
= self
.livestatus_broker
.livestatus
.handle_request(request
)
1565 print "moncululu", response
1566 good_response
= """test_router_0;1;test_host_0,test_host_0/test_ok_0
1568 self
.assert_(self
.lines_equal(response
.strip(), good_response
.strip()))
1570 request
= 'GET hosts\nColumns: host_name\nLimit: 1\n'
1571 response
, keepalive
= self
.livestatus_broker
.livestatus
.handle_request(request
)
1573 good_response
= """test_host_0
1575 # it must be test_host_0 because with Limit: the output is
1576 # alphabetically ordered
1577 self
.assert_(response
== good_response
)
1581 def test_thruk_servicegroup(self
):
1584 self
.update_broker()
1585 #---------------------------------------------------------------
1586 # get services of a certain servicegroup
1587 # test_host_0/test_ok_0 is in
1588 # servicegroup_01,ok via service.servicegroups
1589 # servicegroup_02 via servicegroup.members
1590 #---------------------------------------------------------------
1591 request
= """GET services
1592 Columns: host_name service_description
1593 Filter: groups >= servicegroup_01
1595 ResponseHeader: fixed16
1597 response
, keepalive
= self
.livestatus_broker
.livestatus
.handle_request(request
)
1598 self
.assert_(response
== """200 22
1599 test_host_0;test_ok_0
1601 request
= """GET services
1602 Columns: host_name service_description
1603 Filter: groups >= servicegroup_02
1605 ResponseHeader: fixed16
1607 response
, keepalive
= self
.livestatus_broker
.livestatus
.handle_request(request
)
1608 self
.assert_(response
== """200 22
1609 test_host_0;test_ok_0
1614 def test_is_executing(self
):
1616 #---------------------------------------------------------------
1617 # make sure that the is_executing flag is updated regularly
1618 #---------------------------------------------------------------
1620 host
= self
.sched
.hosts
.find_by_name("test_host_0")
1621 host
.checks_in_progress
= []
1622 host
.act_depend_of
= [] # ignore the router
1623 router
= self
.sched
.hosts
.find_by_name("test_router_0")
1624 router
.checks_in_progress
= []
1625 router
.act_depend_of
= [] # ignore the router
1626 svc
= self
.sched
.services
.find_srv_by_name_and_hostname("test_host_0", "test_ok_0")
1627 svc
.checks_in_progress
= []
1628 svc
.act_depend_of
= [] # no hostchecks on critical checkresults
1630 for loop
in range(1, 2):
1631 print "processing check", loop
1632 self
.show_broks("update_in_checking")
1633 svc
.update_in_checking()
1634 self
.show_broks("fake_check")
1635 self
.fake_check(svc
, 2, 'BAD')
1636 self
.show_broks("sched.consume_results")
1637 self
.sched
.consume_results()
1638 self
.show_broks("sched.get_new_actions")
1639 self
.sched
.get_new_actions()
1640 self
.show_broks("sched.get_new_broks")
1641 self
.sched
.get_new_broks()
1642 self
.show_broks("sched.delete_zombie_checks")
1643 self
.sched
.delete_zombie_checks()
1644 self
.show_broks("sched.delete_zombie_actions")
1645 self
.sched
.delete_zombie_actions()
1646 self
.show_broks("sched.get_to_run_checks")
1647 checks
= self
.sched
.get_to_run_checks(True, False)
1648 self
.show_broks("sched.get_to_run_checks")
1649 actions
= self
.sched
.get_to_run_checks(False, True)
1650 #self.show_actions()
1652 a
.status
= 'inpoller'
1653 a
.check_time
= time
.time()
1655 self
.sched
.put_results(a
)
1656 #self.show_actions()
1658 svc
.checks_in_progress
= []
1659 self
.show_broks("sched.update_downtimes_and_comments")
1660 self
.sched
.update_downtimes_and_comments()
1663 print "-------------------------------------------------"
1664 for brok
in sorted(self
.sched
.broks
.values(), lambda x
, y
: x
.id - y
.id):
1665 if re
.compile('^service_').match(brok
.type):
1666 print "BROK:", brok
.type
1667 print "BROK ", brok
.data
['in_checking']
1668 self
.update_broker()
1669 print "-------------------------------------------------"
1670 request
= 'GET services\nColumns: service_description is_executing\n'
1671 response
, keepalive
= self
.livestatus_broker
.livestatus
.handle_request(request
)
1676 def test_pnp_path(self
):
1679 self
.update_broker()
1680 #---------------------------------------------------------------
1681 # pnp_path is a parameter for the module
1682 # column pnpgraph_present checks if a file
1683 # <pnp_path>/host/service.xml
1684 # <pnp_path>/host/_HOST_.xml
1686 #---------------------------------------------------------------
1687 pnp_path
= self
.pnp4nagios
1689 os
.removedirs(pnp_path
)
1693 print "there is no spool dir", pnp_path
1695 request
= """GET services
1696 Columns: host_name service_description pnpgraph_present
1698 ResponseHeader: fixed16
1700 requesth
= """GET hosts
1701 Columns: host_name pnpgraph_present
1703 ResponseHeader: fixed16
1705 response
, keepalive
= self
.livestatus_broker
.livestatus
.handle_request(request
)
1707 self
.assert_(response
== """200 24
1708 test_host_0;test_ok_0;0
1710 #self.assert_(not self.livestatus_broker.livestatus.pnp_path)
1713 os
.makedirs(pnp_path
)
1714 print "there is an empty spool dir", pnp_path
1718 response
, keepalive
= self
.livestatus_broker
.livestatus
.handle_request(request
)
1720 self
.assert_(response
== """200 24
1721 test_host_0;test_ok_0;0
1723 self
.assert_(self
.livestatus_broker
.livestatus
.pnp_path
== pnp_path
+ '/')
1726 os
.makedirs(pnp_path
+ '/test_host_0')
1727 open(pnp_path
+ '/test_host_0/_HOST_.xml', 'w').close()
1728 open(pnp_path
+ '/test_host_0/test_ok_0.xml', 'w').close()
1729 print "there is a spool dir with data", pnp_path
1733 response
, keepalive
= self
.livestatus_broker
.livestatus
.handle_request(request
)
1735 self
.assert_(response
== """200 24
1736 test_host_0;test_ok_0;1
1738 response
, keepalive
= self
.livestatus_broker
.livestatus
.handle_request(requesth
)
1740 goodresponse
= """200 30
1744 self
.assert_(self
.lines_equal(response
, goodresponse
))
1747 def test_thruk_action_notes_url(self
):
1750 self
.update_broker()
1751 request
= """GET services
1752 Columns: host_name service_description action_url
1753 Filter: host_name = test_host_0
1754 Filter: service_description = test_ok_0
1756 ResponseHeader: fixed16
1758 response
, keepalive
= self
.livestatus_broker
.livestatus
.handle_request(request
)
1759 self
.assert_(response
== """200 78
1760 test_host_0;test_ok_0;/nagios/pnp/index.php?host=$HOSTNAME$&srv=$SERVICEDESC$
1763 request
= """GET services
1764 Columns: host_name service_description action_url_expanded
1765 Filter: host_name = test_host_0
1766 Filter: service_description = test_ok_0
1768 ResponseHeader: fixed16
1770 response
, keepalive
= self
.livestatus_broker
.livestatus
.handle_request(request
)
1771 self
.assert_(response
== """200 75
1772 test_host_0;test_ok_0;/nagios/pnp/index.php?host=test_host_0&srv=test_ok_0
1775 request
= """GET hosts
1776 Columns: host_name action_url_expanded notes_url_expanded
1777 Filter: host_name = test_host_0
1779 ResponseHeader: fixed16
1781 response
, keepalive
= self
.livestatus_broker
.livestatus
.handle_request(request
)
1782 self
.assert_(response
== """200 85
1783 test_host_0;/nagios/pnp/index.php?host=test_host_0;/nagios/wiki/doku.php/test_host_0
1787 def test_thruk_custom_variables(self
):
1790 self
.update_broker()
1791 request
= """GET hosts
1792 Columns: host_name custom_variable_names custom_variable_values
1793 Filter: host_name = test_host_0
1795 ResponseHeader: fixed16
1797 response
, keepalive
= self
.livestatus_broker
.livestatus
.handle_request(request
)
1798 self
.assert_(response
== """200 42
1799 test_host_0;OSLICENSE,OSTYPE;gpl,gnulinux
1802 request
= """GET services
1803 Columns: host_name service_description custom_variable_names custom_variable_values
1804 Filter: host_name = test_host_0
1805 Filter: service_description = test_ok_0
1807 ResponseHeader: fixed16
1809 response
, keepalive
= self
.livestatus_broker
.livestatus
.handle_request(request
)
1810 self
.assert_(response
== """200 41
1811 test_host_0;test_ok_0;CUSTNAME;custvalue
1815 def test_multisite_in_check_period(self
):
1817 self
.update_broker()
1818 # timeperiods must be manipulated in the broker, because status-broks
1819 # contain timeperiod names, not objects.
1820 lshost
= self
.livestatus_broker
.find_host("test_host_0")
1822 localnow
= time
.localtime(now
)
1823 if localnow
[5] > 45:
1825 nextminute
= time
.localtime(time
.time() + 60)
1826 tonextminute
= '%s 00:00-%02d:%02d' % (['monday', 'tuesday', 'wednesday', 'thursday', 'friday', 'saturday', 'sunday'][nextminute
[6]], nextminute
[3], nextminute
[4])
1827 fromnextminute
= '%s %02d:%02d-23:59' % (['monday', 'tuesday', 'wednesday', 'thursday', 'friday', 'saturday', 'sunday'][nextminute
[6]], nextminute
[3], nextminute
[4])
1829 lshost
.notification_period
= Timeperiod()
1830 lshost
.notification_period
.resolve_daterange(lshost
.notification_period
.dateranges
, tonextminute
)
1831 lshost
.check_period
= Timeperiod()
1832 lshost
.check_period
.resolve_daterange(lshost
.check_period
.dateranges
, fromnextminute
)
1833 self
.update_broker()
1834 print "now it is", time
.asctime()
1835 print "notification_period is", tonextminute
1836 print "check_period is", fromnextminute
1837 request
= """GET hosts
1838 Columns: host_name in_notification_period in_check_period
1839 Filter: host_name = test_host_0
1841 ResponseHeader: fixed16
1844 # inside notification_period, outside check_period
1846 response
, keepalive
= self
.livestatus_broker
.livestatus
.handle_request(request
)
1847 self
.assert_(response
== """200 16
1851 # a minute later it's the other way round
1852 response
, keepalive
= self
.livestatus_broker
.livestatus
.handle_request(request
)
1853 self
.assert_(response
== """200 16
1858 def test_thruk_log_current_groups(self
):
1861 b
= Brok('log', {'log' : "[%lu] EXTERNAL COMMAND: [%lu] DISABLE_NOTIFICATIONS" % (now
, now
) })
1862 self
.livestatus_broker
.manage_log_brok(b
)
1863 b
= Brok('log', {'log' : "[%lu] EXTERNAL COMMAND: [%lu] STOP_EXECUTING_SVC_CHECKS" % (now
, now
) })
1864 self
.livestatus_broker
.manage_log_brok(b
)
1865 self
.update_broker()
1866 host
= self
.sched
.hosts
.find_by_name("test_host_0")
1867 host
.checks_in_progress
= []
1868 host
.act_depend_of
= [] # ignore the router
1869 router
= self
.sched
.hosts
.find_by_name("test_router_0")
1870 router
.checks_in_progress
= []
1871 router
.act_depend_of
= [] # ignore the router
1872 svc
= self
.sched
.services
.find_srv_by_name_and_hostname("test_host_0", "test_ok_0")
1873 svc
.checks_in_progress
= []
1874 svc
.act_depend_of
= [] # no hostchecks on critical checkresults
1875 self
.update_broker()
1876 self
.scheduler_loop(1, [[host
, 0, 'UP'], [router
, 0, 'UP'], [svc
, 1, 'WARNING']])
1877 self
.update_broker()
1878 # select messages which are not host or service related. current_service_groups must be an empty list
1879 request
= """GET log
1880 Filter: current_host_name =
1881 Filter: current_service_description =
1883 Columns: message current_service_groups
1885 response
, keepalive
= self
.livestatus_broker
.livestatus
.handle_request(request
)
1886 request
= """GET log
1887 Filter: current_host_name =
1888 Filter: current_service_description =
1890 Columns: message current_service_groups
1893 response
, keepalive
= self
.livestatus_broker
.livestatus
.handle_request(request
)
1894 good_response
= "[[\"[%lu] EXTERNAL COMMAND: [%lu] DISABLE_NOTIFICATIONS\",[]],[\"[%lu] EXTERNAL COMMAND: [%lu] STOP_EXECUTING_SVC_CHECKS\",[]]]\n" % (now
, now
, now
, now
)
1896 self
.assert_(response
== good_response
)
1898 request
= """GET log
1899 Columns: time current_host_name current_service_description current_host_groups current_service_groups
1900 Filter: time >= """ + str(int(now
)) + """
1901 Filter: current_host_name = test_host_0
1902 Filter: current_service_description = test_ok_0
1904 good_response
= """1234567890;test_host_0;test_ok_0;hostgroup_01,allhosts,up;servicegroup_02,ok,servicegroup_01
1906 response
, keepalive
= self
.livestatus_broker
.livestatus
.handle_request(request
)
1907 # remove the timestamps
1908 good_response
= ';'.join(good_response
.split(';')[1:])
1909 response
= ';'.join(response
.split(';')[1:])
1911 self
.assert_(self
.lines_equal(response
, good_response
))
1914 def test_thruk_empty_stats(self
):
1916 self
.update_broker()
1917 # surely no host object matches with this filter
1918 # nonetheless there must be a line of output
1919 request
= """GET hosts
1920 Filter: has_been_checked = 10
1921 Filter: check_type = 10
1922 Stats: sum percent_state_change
1923 Stats: min percent_state_change
1924 Stats: max percent_state_change
1925 OutputFormat: csv"""
1927 good_response
= """0;0;0"""
1929 response
, keepalive
= self
.livestatus_broker
.livestatus
.handle_request(request
)
1931 self
.assert_(self
.lines_equal(response
, good_response
))
1934 def test_thruk_host_parents(self
):
1936 self
.update_broker()
1937 # surely no host object matches with this filter
1938 # nonetheless there must be a line of output
1939 request
= """GET hosts
1940 Columns: host_name parents
1941 OutputFormat: csv"""
1943 good_response
= """test_router_0;
1944 test_host_0;test_router_0
1947 response
, keepalive
= self
.livestatus_broker
.livestatus
.handle_request(request
)
1949 self
.assert_(self
.lines_equal(response
, good_response
))
1953 def test_statsgroupby(self
):
1957 for host
in self
.sched
.hosts
:
1958 objlist
.append([host
, 0, 'UP'])
1959 for service
in self
.sched
.services
:
1960 objlist
.append([service
, 0, 'OK'])
1961 self
.scheduler_loop(1, objlist
)
1962 self
.update_broker()
1963 svc1
= self
.sched
.services
.find_srv_by_name_and_hostname("test_host_0", "test_ok_0")
1965 self
.scheduler_loop(1, [[svc1
, 1, 'W']])
1966 self
.update_broker()
1968 request
= """GET services
1969 Filter: contacts >= test_contact
1970 Stats: state != 9999
1975 StatsGroupBy: host_name"""
1976 response
, keepalive
= self
.livestatus_broker
.livestatus
.handle_request(request
)
1978 self
.assert_(self
.contains_line(response
, 'test_host_0;1;0;1;0;0'))
1980 request
= """GET services
1981 Stats: state != 9999
1984 response
, keepalive
= self
.livestatus_broker
.livestatus
.handle_request(request
)
1986 # does not show null-values
1987 #self.assert_(self.contains_line(response, '0;0'))
1988 self
.assert_(self
.contains_line(response
, '1;1'))
1989 #self.assert_(self.contains_line(response, '2;0'))
1990 #self.assert_(self.contains_line(response, '3;0'))
1993 def test_multisite_column_groupby(self
):
1997 for host
in self
.sched
.hosts
:
1998 objlist
.append([host
, 0, 'UP'])
1999 for service
in self
.sched
.services
:
2000 objlist
.append([service
, 0, 'OK'])
2001 self
.scheduler_loop(1, objlist
)
2002 self
.update_broker()
2003 router
= self
.sched
.hosts
.find_by_name("test_router_0")
2004 host
= self
.sched
.hosts
.find_by_name("test_host_0")
2005 svc
= self
.sched
.services
.find_srv_by_name_and_hostname("test_host_0", "test_ok_0")
2006 host
.act_depend_of
= []
2007 router
.act_depend_of
= []
2008 self
.scheduler_loop(4, [[router
, 1, 'D'], [host
, 1, 'D'], [svc
, 1, 'W']])
2009 self
.update_broker()
2010 self
.scheduler_loop(1, [[router
, 0, 'U'], [host
, 0, 'U'], [svc
, 0, 'O']])
2011 self
.update_broker()
2012 self
.scheduler_loop(1, [[router
, 1, 'D'], [host
, 0, 'U'], [svc
, 2, 'C']])
2013 self
.update_broker()
2015 request
= """GET log
2016 Columns: host_name service_description
2017 Filter: log_time >= 1292256802
2026 response
, keepalive
= self
.livestatus_broker
.livestatus
.handle_request(request
)
2028 self
.assert_(self
.contains_line(response
, 'test_host_0;;1;3;0;0;3'))
2029 self
.assert_(self
.contains_line(response
, 'test_router_0;;1;4;0;0;4'))
2030 self
.assert_(self
.contains_line(response
, 'test_host_0;test_ok_0;1;2;1;0;3'))
2033 # does not show null-values
2034 #self.assert_(self.contains_line(response, '0;0'))
2035 #self.assert_(self.contains_line(response, '1;1'))
2036 #self.assert_(self.contains_line(response, '2;0'))
2037 #self.assert_(self.contains_line(response, '3;0'))
2041 class TestConfigBig(TestConfig
):
2043 self
.setup_with_file('etc/nagios_5r_100h_2000s.cfg')
2045 self
.testid
= str(os
.getpid() + random
.randint(1, 1000))
2046 self
.livelogs
= 'tmp/livelogs.db' + self
.testid
2047 self
.pnp4nagios
= 'tmp/pnp4nagios_test' + self
.testid
2048 self
.livestatus_broker
= Livestatus_broker(modconf
, '127.0.0.1', str(50000 + os
.getpid()), 'live', [], self
.livelogs
, 365, self
.pnp4nagios
)
2049 self
.livestatus_broker
.create_queues()
2050 #self.livestatus_broker.properties = {
2054 self
.livestatus_broker
.init()
2055 print "Cleaning old broks?"
2056 self
.sched
.fill_initial_broks()
2057 self
.update_broker()
2062 self
.livestatus_broker
.dbconn
.commit()
2063 self
.livestatus_broker
.dbconn
.close()
2064 if os
.path
.exists(self
.livelogs
):
2065 os
.remove(self
.livelogs
)
2066 if os
.path
.exists(self
.pnp4nagios
):
2067 shutil
.rmtree(self
.pnp4nagios
)
2068 if os
.path
.exists('var/nagios.log'):
2069 os
.remove('var/nagios.log')
2070 if os
.path
.exists('var/retention.dat'):
2071 os
.remove('var/retention.dat')
2072 if os
.path
.exists('var/status.dat'):
2073 os
.remove('var/status.dat')
2076 def test_stats(self
):
2078 if self
.nagios_installed():
2079 self
.start_nagios('5r_100h_2000s')
2082 for host
in self
.sched
.hosts
:
2083 objlist
.append([host
, 0, 'UP'])
2084 for service
in self
.sched
.services
:
2085 objlist
.append([service
, 0, 'OK'])
2086 self
.scheduler_loop(1, objlist
)
2087 self
.update_broker()
2088 svc1
= self
.sched
.services
.find_srv_by_name_and_hostname("test_host_005", "test_ok_00")
2090 svc2
= self
.sched
.services
.find_srv_by_name_and_hostname("test_host_005", "test_ok_15")
2092 svc3
= self
.sched
.services
.find_srv_by_name_and_hostname("test_host_005", "test_ok_16")
2094 svc4
= self
.sched
.services
.find_srv_by_name_and_hostname("test_host_007", "test_ok_05")
2096 svc5
= self
.sched
.services
.find_srv_by_name_and_hostname("test_host_007", "test_ok_11")
2097 svc6
= self
.sched
.services
.find_srv_by_name_and_hostname("test_host_025", "test_ok_01")
2098 svc7
= self
.sched
.services
.find_srv_by_name_and_hostname("test_host_025", "test_ok_03")
2099 self
.scheduler_loop(1, [[svc1
, 1, 'W'], [svc2
, 1, 'W'], [svc3
, 1, 'W'], [svc4
, 2, 'C'], [svc5
, 3, 'U'], [svc6
, 2, 'C'], [svc7
, 2, 'C']])
2100 self
.update_broker()
2101 # 1993O, 3xW, 3xC, 1xU
2103 request
= """GET services
2104 Filter: contacts >= test_contact
2105 Stats: state != 9999
2110 response
, keepalive
= self
.livestatus_broker
.livestatus
.handle_request(request
)
2111 print 'query_6_______________\n%s\n%s\n' % (request
, response
)
2112 self
.assert_(response
== '2000;1993;3;3;1\n')
2113 if self
.nagios_installed():
2114 nagresponse
= self
.ask_nagios(request
)
2116 self
.assert_(self
.lines_equal(response
, nagresponse
))
2119 def test_statsgroupby(self
):
2121 if self
.nagios_installed():
2122 self
.start_nagios('5r_100h_2000s')
2125 for host
in self
.sched
.hosts
:
2126 objlist
.append([host
, 0, 'UP'])
2127 for service
in self
.sched
.services
:
2128 objlist
.append([service
, 0, 'OK'])
2129 self
.scheduler_loop(1, objlist
)
2130 self
.update_broker()
2131 svc1
= self
.sched
.services
.find_srv_by_name_and_hostname("test_host_005", "test_ok_00")
2133 svc2
= self
.sched
.services
.find_srv_by_name_and_hostname("test_host_005", "test_ok_15")
2135 svc3
= self
.sched
.services
.find_srv_by_name_and_hostname("test_host_005", "test_ok_16")
2137 svc4
= self
.sched
.services
.find_srv_by_name_and_hostname("test_host_007", "test_ok_05")
2139 svc5
= self
.sched
.services
.find_srv_by_name_and_hostname("test_host_007", "test_ok_11")
2140 svc6
= self
.sched
.services
.find_srv_by_name_and_hostname("test_host_025", "test_ok_01")
2141 svc7
= self
.sched
.services
.find_srv_by_name_and_hostname("test_host_025", "test_ok_03")
2142 self
.scheduler_loop(1, [[svc1
, 1, 'W'], [svc2
, 1, 'W'], [svc3
, 1, 'W'], [svc4
, 2, 'C'], [svc5
, 3, 'U'], [svc6
, 2, 'C'], [svc7
, 2, 'C']])
2143 self
.update_broker()
2144 # 1993O, 3xW, 3xC, 1xU
2146 request
= 'GET services\nFilter: contacts >= test_contact\nStats: state != 9999\nStats: state = 0\nStats: state = 1\nStats: state = 2\nStats: state = 3\nStatsGroupBy: host_name'
2147 response
, keepalive
= self
.livestatus_broker
.livestatus
.handle_request(request
)
2149 self
.assert_(self
.contains_line(response
, 'test_host_005;20;17;3;0;0'))
2150 self
.assert_(self
.contains_line(response
, 'test_host_007;20;18;0;1;1'))
2151 self
.assert_(self
.contains_line(response
, 'test_host_025;20;18;0;2;0'))
2152 self
.assert_(self
.contains_line(response
, 'test_host_026;20;20;0;0;0'))
2154 request
= """GET services
2155 Stats: state != 9999
2158 response
, keepalive
= self
.livestatus_broker
.livestatus
.handle_request(request
)
2160 self
.assert_(self
.contains_line(response
, '0;1993'))
2161 self
.assert_(self
.contains_line(response
, '1;3'))
2162 self
.assert_(self
.contains_line(response
, '2;3'))
2163 self
.assert_(self
.contains_line(response
, '3;1'))
2164 if self
.nagios_installed():
2165 nagresponse
= self
.ask_nagios(request
)
2167 self
.assert_(self
.lines_equal(response
, nagresponse
))
2170 def test_hostsbygroup(self
):
2172 if self
.nagios_installed():
2173 self
.start_nagios('5r_100h_2000s')
2176 for host
in self
.sched
.hosts
:
2177 objlist
.append([host
, 0, 'UP'])
2178 for service
in self
.sched
.services
:
2179 objlist
.append([service
, 0, 'OK'])
2180 self
.scheduler_loop(1, objlist
)
2181 self
.update_broker()
2182 request
= """GET hostsbygroup
2184 Columns: host_name hostgroup_name
2187 ResponseHeader: fixed16
2190 response
, keepalive
= self
.livestatus_broker
.livestatus
.handle_request(request
)
2192 if self
.nagios_installed():
2193 nagresponse
= self
.ask_nagios(request
)
2195 self
.assert_(self
.lines_equal(response
, nagresponse
))
2198 def test_servicesbyhostgroup(self
):
2200 if self
.nagios_installed():
2201 self
.start_nagios('5r_100h_2000s')
2204 for host
in self
.sched
.hosts
:
2205 objlist
.append([host
, 0, 'UP'])
2206 for service
in self
.sched
.services
:
2207 objlist
.append([service
, 0, 'OK'])
2208 self
.scheduler_loop(1, objlist
)
2209 self
.update_broker()
2210 request
= """GET servicesbyhostgroup
2211 Filter: host_groups >= up
2212 Stats: has_been_checked = 0
2214 Stats: has_been_checked != 0
2215 Stats: scheduled_downtime_depth = 0
2216 Stats: host_scheduled_downtime_depth = 0
2219 Stats: scheduled_downtime_depth > 0
2220 Stats: host_scheduled_downtime_depth > 0
2223 Stats: acknowledged = 0
2224 Stats: host_acknowledged = 0
2225 Stats: scheduled_downtime_depth = 0
2226 Stats: host_scheduled_downtime_depth = 0
2229 Stats: acknowledged = 1
2230 Stats: host_acknowledged = 1
2234 Stats: scheduled_downtime_depth > 0
2235 Stats: host_scheduled_downtime_depth > 0
2239 Stats: acknowledged = 0
2240 Stats: host_acknowledged = 0
2241 Stats: scheduled_downtime_depth = 0
2242 Stats: host_scheduled_downtime_depth = 0
2245 Stats: acknowledged = 1
2246 Stats: host_acknowledged = 1
2250 Stats: scheduled_downtime_depth > 0
2251 Stats: host_scheduled_downtime_depth > 0
2255 Stats: acknowledged = 0
2256 Stats: host_acknowledged = 0
2257 Stats: scheduled_downtime_depth = 0
2258 Stats: host_scheduled_downtime_depth = 0
2261 Stats: acknowledged = 1
2262 Stats: host_acknowledged = 1
2266 Stats: scheduled_downtime_depth > 0
2267 Stats: host_scheduled_downtime_depth > 0
2270 StatsGroupBy: hostgroup_name
2273 ResponseHeader: fixed16
2276 response
, keepalive
= self
.livestatus_broker
.livestatus
.handle_request(request
)
2278 print "livestatus duration %f" % (tac
- tic
)
2280 if self
.nagios_installed():
2281 nagresponse
= self
.ask_nagios(request
)
2283 self
.assert_(self
.lines_equal(response
, nagresponse
))
2285 # Again, without Filter:
2286 request
= """GET servicesbyhostgroup
2287 Stats: has_been_checked = 0
2289 Stats: has_been_checked != 0
2290 Stats: scheduled_downtime_depth = 0
2291 Stats: host_scheduled_downtime_depth = 0
2294 Stats: scheduled_downtime_depth > 0
2295 Stats: host_scheduled_downtime_depth > 0
2298 Stats: acknowledged = 0
2299 Stats: host_acknowledged = 0
2300 Stats: scheduled_downtime_depth = 0
2301 Stats: host_scheduled_downtime_depth = 0
2304 Stats: acknowledged = 1
2305 Stats: host_acknowledged = 1
2309 Stats: scheduled_downtime_depth > 0
2310 Stats: host_scheduled_downtime_depth > 0
2314 Stats: acknowledged = 0
2315 Stats: host_acknowledged = 0
2316 Stats: scheduled_downtime_depth = 0
2317 Stats: host_scheduled_downtime_depth = 0
2320 Stats: acknowledged = 1
2321 Stats: host_acknowledged = 1
2325 Stats: scheduled_downtime_depth > 0
2326 Stats: host_scheduled_downtime_depth > 0
2330 Stats: acknowledged = 0
2331 Stats: host_acknowledged = 0
2332 Stats: scheduled_downtime_depth = 0
2333 Stats: host_scheduled_downtime_depth = 0
2336 Stats: acknowledged = 1
2337 Stats: host_acknowledged = 1
2341 Stats: scheduled_downtime_depth > 0
2342 Stats: host_scheduled_downtime_depth > 0
2345 StatsGroupBy: hostgroup_name
2348 ResponseHeader: fixed16
2350 response
, keepalive
= self
.livestatus_broker
.livestatus
.handle_request(request
)
2352 if self
.nagios_installed():
2353 nagresponse
= self
.ask_nagios(request
)
2355 self
.assert_(self
.lines_equal(response
, nagresponse
))
2358 def test_childs(self
):
2359 if self
.nagios_installed():
2360 self
.start_nagios('5r_100h_2000s')
2364 for host
in self
.sched
.hosts
:
2365 objlist
.append([host
, 0, 'UP'])
2366 for service
in self
.sched
.services
:
2367 objlist
.append([service
, 0, 'OK'])
2368 self
.scheduler_loop(1, objlist
)
2369 self
.update_broker()
2370 request
= """GET hosts
2372 Filter: name = test_host_0
2375 ResponseHeader: fixed16
2377 response
, keepalive
= self
.livestatus_broker
.livestatus
.handle_request(request
)
2379 if self
.nagios_installed():
2380 nagresponse
= self
.ask_nagios(request
)
2381 print "nagresponse----------------------------------------------"
2383 self
.assert_(self
.lines_equal(response
, nagresponse
))
2384 request
= """GET hosts
2386 Filter: name = test_router_0
2389 ResponseHeader: fixed16
2391 response
, keepalive
= self
.livestatus_broker
.livestatus
.handle_request(request
)
2393 if self
.nagios_installed():
2394 nagresponse
= self
.ask_nagios(request
)
2395 print "nagresponse----------------------------------------------"
2397 self
.assert_(self
.lines_equal(response
, nagresponse
))
2400 def test_thruk_servicegroup(self
):
2403 self
.update_broker()
2404 #---------------------------------------------------------------
2405 # get services of a certain servicegroup
2406 # test_host_0/test_ok_0 is in
2407 # servicegroup_01,ok via service.servicegroups
2408 # servicegroup_02 via servicegroup.members
2409 #---------------------------------------------------------------
2410 request
= """GET services
2411 Columns: host_name service_description
2412 Filter: groups >= servicegroup_01
2414 ResponseHeader: fixed16
2416 # 400 services => 400 lines + header + empty last line
2417 response
, keepalive
= self
.livestatus_broker
.livestatus
.handle_request(request
)
2419 self
.assert_(len(response
.split("\n")) == 402)
2421 request
= """GET servicegroups
2422 Columns: name members
2423 Filter: name = servicegroup_01
2426 # 400 services => 400 lines
2427 response
, keepalive
= self
.livestatus_broker
.livestatus
.handle_request(request
)
2429 # take first line, take members column, count list elements = 400 services
2430 self
.assert_(len(((response
.split("\n")[0]).split(';')[1]).split(',')) == 400)
2433 class TestConfigComplex(TestConfig
):
2435 self
.setup_with_file('etc/nagios_problem_impact.cfg')
2436 self
.testid
= str(os
.getpid() + random
.randint(1, 1000))
2437 self
.livelogs
= 'tmp/livelogs.db' + self
.testid
2438 self
.pnp4nagios
= 'tmp/pnp4nagios_test' + self
.testid
2439 self
.livestatus_broker
= Livestatus_broker(modconf
, '127.0.0.1', str(50000 + os
.getpid()), 'live', [], self
.livelogs
, 365, self
.pnp4nagios
)
2440 self
.livestatus_broker
.create_queues()
2441 self
.livestatus_broker
.init()
2442 print "Cleaning old broks?"
2443 self
.sched
.fill_initial_broks()
2444 self
.update_broker()
2445 self
.nagios_path
= None
2446 self
.livestatus_path
= None
2447 self
.nagios_config
= None
2452 self
.livestatus_broker
.dbconn
.commit()
2453 self
.livestatus_broker
.dbconn
.close()
2454 if os
.path
.exists(self
.livelogs
):
2455 os
.remove(self
.livelogs
)
2456 if os
.path
.exists(self
.pnp4nagios
):
2457 shutil
.rmtree(self
.pnp4nagios
)
2460 # test_host_0 has parents test_router_0,test_router_1
2461 def test_thruk_parents(self
):
2465 for host
in self
.sched
.hosts
:
2466 objlist
.append([host
, 0, 'UP'])
2467 for service
in self
.sched
.services
:
2468 objlist
.append([service
, 0, 'OK'])
2469 self
.scheduler_loop(1, objlist
)
2470 self
.update_broker()
2471 request
= """GET hosts
2472 Columns: host_name parents childs
2475 good_response
= """test_router_0;;test_host_0,test_host_1
2476 test_router_1;;test_host_0,test_host_1
2477 test_host_0;test_router_0,test_router_1;
2478 test_host_1;test_router_0,test_router_1;
2480 response
, keepalive
= self
.livestatus_broker
.livestatus
.handle_request(request
)
2482 self
.assert_(self
.lines_equal(response
, good_response
))
2486 if __name__
== '__main__':
2488 command
= """unittest.main()"""
2490 #cProfile.runctx( command, globals(), locals(), filename="Thruk.profile" )