def linkify_one_command_with_commands(self, commands, prop): if hasattr(self, prop): command = getattr(self, prop).strip() if command != '': if hasattr(self, 'poller_tag'): cmdCall = CommandCall(commands, command, poller_tag=self.poller_tag) elif hasattr(self, 'reactionner_tag'): cmdCall = CommandCall(commands, command, reactionner_tag=self.reactionner_tag) else: cmdCall = CommandCall(commands, command) setattr(self, prop, cmdCall) else: setattr(self, prop, None)
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.assertEqual('check_command_test', c.command_name) b = c.get_initial_status_brok() self.assertEqual('initial_command_status', b.type) # now create a commands packs cs = Commands([c]) dummy_call = "check_command_test!titi!toto" cc = CommandCall(cs, dummy_call) self.assertEqual(True, cc.is_valid()) self.assertEqual(c, cc.command) self.assertEqual('DMZ', cc.poller_tag)
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')
def test_special_macros_realm(self): mr = self.get_mr() (svc, hst) = self.get_hst_svc() data = svc.get_data_for_checks() hst.state = 'UP' dummy_call = "special_macro!$HOSTREALM$" cc = CommandCall(self.conf.commands, dummy_call) com = mr.resolve_command(cc, data) print com self.assert_(com == 'plugins/nothing Default')
def test_special_macros(self): mr = self.get_mr() (svc, hst) = self.get_hst_svc() data = svc.get_data_for_checks() hst.state = 'UP' dummy_call = "special_macro!$TOTALHOSTSUP$" cc = CommandCall(self.conf.commands, dummy_call) com = mr.resolve_command(cc, data) print com self.assertEqual('plugins/nothing 1', com)
def create_commandcall(self,prop, commands, command): comandcall = dict(commands=commands, call=command) if hasattr(prop, 'enable_environment_macros'): comandcall['enable_environment_macros'] = prop.enable_environment_macros if hasattr(prop, 'poller_tag'): comandcall['poller_tag']=prop.poller_tag elif hasattr(prop, 'reactionner_tag'): comandcall['reactionner_tag']=prop.reactionner_tag return CommandCall(**comandcall)
def test_hostadressX_macros(self): mr = self.get_mr() (svc, hst) = self.get_hst_svc() data = hst.get_data_for_checks() # Ok sample host call dummy_call = "special_macro!$HOSTADDRESS6$" cc = CommandCall(self.conf.commands, dummy_call) com = mr.resolve_command(cc, data) print com self.assert_(com == 'plugins/nothing ::1')
def linkify_one_command_with_commands(self, commands, prop): for i in self: if hasattr(i, prop): command = getattr(i, prop).strip() if command != '': if hasattr(i, 'poller_tag'): cmdCall = CommandCall(commands, command, poller_tag=i.poller_tag) elif hasattr(i, 'reactionner_tag'): cmdCall = CommandCall( commands, command, reactionner_tag=i.reactionner_tag) else: cmdCall = CommandCall(commands, command) # TODO: catch None? setattr(i, prop, cmdCall) else: setattr(i, prop, None)
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')