def test_resource_file(self): mr = self.get_mr() (svc, hst) = self.get_hst_svc() data = svc.get_data_for_checks() dummy_call = "special_macro!$USER1$" cc = CommandCall(self.conf.commands, dummy_call) com = mr.resolve_command(cc, data) self.assert_(com == 'plugins/nothing plugins') dummy_call = "special_macro!$INTERESTINGVARIABLE$" cc = CommandCall(self.conf.commands, dummy_call) com = mr.resolve_command(cc, data) print "CUCU", com self.assert_(com == 'plugins/nothing interestingvalue') # Look for multiple = in lines, should split the first # and keep others in the macro value dummy_call = "special_macro!$ANOTHERVALUE$" cc = CommandCall(self.conf.commands, dummy_call) com = mr.resolve_command(cc, data) print "CUCU", com self.assert_(com == 'plugins/nothing blabla=toto')
def test_ondemand_macros(self): mr = self.get_mr() (svc, hst) = self.get_hst_svc() data = hst.get_data_for_checks() hst.state = 'UP' svc.state = 'UNKNOWN' # Ok sample host call dummy_call = "special_macro!$HOSTSTATE:test_host_0$" cc = CommandCall(self.conf.commands, dummy_call) com = mr.resolve_command(cc, data) print com self.assert_(com == 'plugins/nothing UP') # Call with a void host name, means : myhost data = hst.get_data_for_checks() dummy_call = "special_macro!$HOSTSTATE:$" cc = CommandCall(self.conf.commands, dummy_call) com = mr.resolve_command(cc, data) print com self.assert_(com == 'plugins/nothing UP') # Now with a service, for our implicit host state data = svc.get_data_for_checks() dummy_call = "special_macro!$HOSTSTATE:test_host_0$" cc = CommandCall(self.conf.commands, dummy_call) com = mr.resolve_command(cc, data) print com self.assert_(com == 'plugins/nothing UP') # Now with a service, for our implicit host state data = svc.get_data_for_checks() dummy_call = "special_macro!$HOSTSTATE:$" cc = CommandCall(self.conf.commands, dummy_call) com = mr.resolve_command(cc, data) print com self.assert_(com == 'plugins/nothing UP') # Now prepare another service svc2 = self.sched.services.find_srv_by_name_and_hostname("test_host_0", "test_another_service") svc2.output = 'you should not pass' # Now call this data from our previous service data = svc.get_data_for_checks() dummy_call = "special_macro!$SERVICEOUTPUT:test_host_0:test_another_service$" cc = CommandCall(self.conf.commands, dummy_call) com = mr.resolve_command(cc, data) print com self.assert_(com == 'plugins/nothing you should not pass') # Ok now with an host implicit way data = svc.get_data_for_checks() dummy_call = "special_macro!$SERVICEOUTPUT::test_another_service$" cc = CommandCall(self.conf.commands, dummy_call) com = mr.resolve_command(cc, data) print com self.assert_(com == 'plugins/nothing you should not pass')
def linkify_command_list_with_commands(self, commands, prop): for i in self: if hasattr(i, prop): coms = getattr(i, prop).split(',') coms = strip_and_uniq(coms) com_list = [] for com in coms: if com != '': if hasattr(i, 'poller_tag'): cmdCall = CommandCall(commands, com, poller_tag=i.poller_tag) elif hasattr(i, 'reactionner_tag'): cmdCall = CommandCall( commands, com, reactionner_tag=i.reactionner_tag) else: cmdCall = CommandCall(commands, com) # TODO: catch None? com_list.append(cmdCall) else: # TODO: catch? pass setattr(i, prop, com_list)
def test_illegal_macro_output_chars(self): "$HOSTOUTPUT$, $HOSTPERFDATA$, $HOSTACKAUTHOR$, $HOSTACKCOMMENT$, $SERVICEOUTPUT$, $SERVICEPERFDATA$, $SERVICEACKAUTHOR$, and $SERVICEACKCOMMENT$ " mr = self.get_mr() (svc, hst) = self.get_hst_svc() data = svc.get_data_for_checks() illegal_macro_output_chars = self.sched.conf.illegal_macro_output_chars print "Illegal macros caracters:", illegal_macro_output_chars hst.output = 'monculcestdupoulet' dummy_call = "special_macro!$HOSTOUTPUT$" for c in illegal_macro_output_chars: hst.output = 'monculcestdupoulet' + c cc = CommandCall(self.conf.commands, dummy_call) com = mr.resolve_command(cc, data) print com self.assert_(com == 'plugins/nothing monculcestdupoulet')
def test_command(self): t = {'command_name': 'check_command_test', 'command_line': '/tmp/dummy_command.sh $ARG1$ $ARG2$', 'poller_tag': 'DMZ' } c = Command(t) self.assert_(c.command_name == 'check_command_test') b = c.get_initial_status_brok() self.assert_(b.type == 'initial_command_status') # now create a commands packs cs = Commands([c]) dummy_call = "check_command_test!titi!toto" cc = CommandCall(cs, dummy_call) self.assert_(cc.is_valid() == True) self.assert_(cc.command == c) self.assert_(cc.poller_tag == 'DMZ')