예제 #1
0
def init(pid, plugin_alias, script_alias):
    global plugin_id, icinga_url, icinga_auth, path
    plugin_id = pid

    core = Core.get(plugin_id)
    path = core.expand_path("${module-path}")

    conf = Settings.get(plugin_id)
    conf.register_path(
        '/settings/remote-modules', "Remote module",
        "Keys for the remote-modules module which handles downloading remote modules on demand"
    )
    conf.register_path(
        '/settings/remote-modules/modules', "Remote modules",
        "A list of remote modules to fetch the key is not used.")

    reg = Registry.get(plugin_id)
    reg.simple_function('remote_module_update', update,
                        'Update all or one remote module')

    for mod in conf.get_section('/settings/remote-modules/modules'):
        url = conf.get_string('/settings/remote-modules/modules', mod, '')
        log("Adding module %s as %s" % (mod, url))
        conf.register_key('/settings/remote-modules/modules', mod, 'string',
                          "A remote module to fetch",
                          "A remote module to fetch", "")
    if not update_modules():
        log_error("Failed to update modules")
    else:
        enable_modules()
예제 #2
0
    def run(self, arguments=[]):
        cases = []
        try:
            parser = ThrowingArgumentParser(prog='nscp')
            parser.add_argument("--script",
                                help="The script to run (sort of ignored)",
                                action='store')
            parser.add_argument("--case",
                                help="Which test case to run",
                                action='append')
            args = parser.parse_args(arguments)
            cases = args.case
        except Exception as e:
            log_error('Failed to parse command line: %s' % e)

        result = TestResult('Test result for %d suites' % len(self.suites))
        for suite in self.suites:
            instance = suite.getInstance()
            instance.setup(self.plugin_id, self.prefix)
            suite_result = TestResult('Running suite: %s' % instance.title())
            if cases:
                suite_result.append(instance.run_test(cases))
            else:
                suite_result.append(instance.run_test())
            result.append(suite_result)
            result.add_message(suite_result.is_ok(),
                               'Result from suite: %s' % instance.title())
            instance.teardown()
        return result
예제 #3
0
    def do_one_test(self,
                    script,
                    expected=status.OK,
                    message="Foo Bar",
                    args=[],
                    cleanup=True):
        result = TestResult('%s (%s)' % (script, args))
        (ret, msg, perf) = self.core.simple_query(script, args)
        if cleanup and os.name != 'nt':
            message = message.replace('"', '')
            message = message.replace('$ARG1$', '$')
            message = message.replace('$ARG2$', '$')
            message = message.replace('$ARG3$', '$')

        message = message.replace('\r', '\n')
        message = message.replace('\n\n', '\n')
        msg = msg.replace('\r', '\n')
        msg = msg.replace('\n\n', '\n')

        result.assert_equals(ret, expected,
                             'Validate return code for %s' % script)
        result.assert_equals(msg, message,
                             'Validate return message for %s' % script)
        if msg != message:
            diff = difflib.ndiff(msg.splitlines(1), message.splitlines(1))
            for l in diff:
                log_error(l)
        return result
예제 #4
0
파일: test_helper.py 프로젝트: wytcld/nscp
 def log(self, show_all = False, prefix = '', indent = 0):
     if self.status:
         if show_all:
             log('%s%s%s'%(prefix, ''.rjust(indent, ' '), self))
         log_debug('%s%s%s'%(prefix, ''.rjust(indent, ' '), self))
     else:
         log_error('%s%s%s'%(prefix, ''.rjust(indent, ' '), self))
예제 #5
0
파일: test_helper.py 프로젝트: r1se/nscp
	def log(self, prefix = '', indent = 0):
		start = '%s%s'%(prefix, ''.rjust(indent, ' '))
		if self.status:
			log_debug('%s%s'%(start, self))
		else:
			log_error('%s%s'%(start, self))
		for c in self.children:
			c.log(prefix, indent+1)
예제 #6
0
	def log(self, prefix = '', indent = 0):
		start = '%s%s'%(prefix, ''.rjust(indent, ' '))
		if self.status:
			log_debug('%s%s'%(start, self))
		else:
			log_error('%s%s'%(start, self))
		for c in self.children:
			c.log(prefix, indent+1)
예제 #7
0
파일: test_helper.py 프로젝트: jkells/nscp
 def log(self, prefix="", indent=0):
     start = "%s%s" % (prefix, "".rjust(indent, " "))
     if self.status:
         log_debug("%s%s" % (start, self))
     else:
         log_error("%s%s" % (start, self))
     for c in self.children:
         c.log(prefix, indent + 1)
예제 #8
0
파일: test_helper.py 프로젝트: r1se/nscp
	def append(self, entry):
		if not entry:
			log_error('Attempting to add invalid entry (None)')
		elif entry == self:
			log_error('Attempting to add self to self')
		else:
			if self.status and not entry.is_ok():
				self.status = False
			self.children.append(entry)
예제 #9
0
파일: test_helper.py 프로젝트: jkells/nscp
 def append(self, entry):
     if not entry:
         log_error("Attempting to add invalid entry (None)")
     elif entry == self:
         log_error("Attempting to add self to self")
     else:
         if self.status and not entry.is_ok():
             self.status = False
         self.children.append(entry)
예제 #10
0
 def get_plugins(self):
     (code, data) = self.registry.query(self.build_command_request(4))
     if code == 1:
         message = plugin_pb2.RegistryResponseMessage()
         message.ParseFromString(data)
         for payload in message.payload:
             if payload.inventory:
                 log_debug('Found %d plugins' % len(payload.inventory))
                 return payload.inventory
     log_error('No plugins')
     return []
예제 #11
0
파일: docs.py 프로젝트: borgified/nscp
	def get_plugins(self):
		(code, data) = self.registry.query(self.build_command_request(4))
		if code == 1:
			message = plugin_pb2.RegistryResponseMessage()
			message.ParseFromString(data)
			for payload in message.payload:
				if payload.inventory:
					log_debug('Found %d plugins'%len(payload.inventory))
					return payload.inventory
		log_error('No plugins')
		return []
예제 #12
0
파일: docs.py 프로젝트: Fox-Alpha/nscp
 def get_query_aliases(self):
     log_debug('Fetching aliases...')
     (code, data) = self.registry.query(self.build_command_request(5))
     if code == 1:
         message = plugin_pb2.RegistryResponseMessage()
         message.ParseFromString(data)
         for payload in message.payload:
             if payload.inventory:
                 log_debug('Found %d aliases' % len(payload.inventory))
                 return payload.inventory
     log_error('No aliases found')
     return []
예제 #13
0
    def handler_wrapped(self, channel, request):
        log_error('DISCARDING message on %s' % (channel))

        message = plugin_pb2.SubmitRequestMessage()
        message.ParseFromString(request)
        command = message.payload[0].command
        log('Got message %s on %s' % (command, channel))

        msg = self.get_response(command)
        msg.got_response = True
        self.set_response(msg)
        return None
예제 #14
0
파일: docs.py 프로젝트: ossmon/nscp
	def get_query_aliases(self):
		log_debug('Fetching aliases...')
		(code, data) = self.registry.query(self.build_command_request(5))
		if code == 1:
			message = plugin_pb2.RegistryResponseMessage()
			message.ParseFromString(data)
			for payload in message.payload:
				if payload.inventory:
					log_debug('Found %d aliases'%len(payload.inventory))
					return payload.inventory
		log_error('No aliases found')
		return []
예제 #15
0
파일: test_nrpe.py 프로젝트: Fox-Alpha/nscp
	def handler_wrapped(self, channel, request):
		log_error('DISCARDING message on %s'%(channel))
		
		message = plugin_pb2.SubmitRequestMessage()
		message.ParseFromString(request)
		command = message.payload[0].command
		log('Got message %s on %s'%(command, channel))
		
		msg = self.get_response(command)
		msg.got_response = True
		self.set_response(msg)
		return None
예제 #16
0
	def inbox_handler_wrapped(self, channel, request):
		message = plugin_pb2.SubmitRequestMessage()
		message.ParseFromString(request)
		if len(message.payload) != 1:
			log_error("Got invalid message on channel: %s"%channel)
			return None
		command = message.payload[0].command
		log_debug('Got message %s on %s'%(command, channel))
		
		msg = NSCAMessage(command)
		msg.got_response = True
		self.set_response(msg)
		return None
예제 #17
0
    def inbox_handler_wrapped(self, channel, request):
        message = plugin_pb2.SubmitRequestMessage()
        message.ParseFromString(request)
        if len(message.payload) != 1:
            log_error("Got invalid message on channel: %s" % channel)
            return None
        command = message.payload[0].command
        log('Got message %s on %s' % (command, channel))

        msg = NSCAMessage(command)
        msg.got_response = True
        self.set_response(msg)
        return None
예제 #18
0
def __main__(args):
    global plugin_id
    # List all namespaces recursivly
    core = Core.get(plugin_id)
    (ret, ns_msgs) = core.simple_exec('CheckWMI', 'wmi', ['--list-all-ns'])
    if len(ns_msgs) == 0:
        log_error("Failed to execute WMI command is CheckWMI enabled?")
    else:
        for ns in ns_msgs[0].splitlines():
            # List all classes in each namespace
            (ret, cls_msgs) = core.simple_exec('any', 'wmi', ['--list-classes', '--simple', '--namespace', ns])
            for cls in cls_msgs[0].splitlines():
                log( '%s : %s'%(ns, cls))
예제 #19
0
파일: test_helper.py 프로젝트: r1se/nscp
	def extend(self, lst):
		if isinstance(lst, list):
			if self.status:
				for c in lst:
					if not c.is_ok():
						self.status = False
						
			for c in lst:
				if c.contains(self):
					log_error('Attempting to add a list with me in it')
					return
			self.children.extend(lst)
		else:
			self.append(lst)
예제 #20
0
파일: test_helper.py 프로젝트: jkells/nscp
    def extend(self, lst):
        if isinstance(lst, list):
            if self.status:
                for c in lst:
                    if not c.is_ok():
                        self.status = False

            for c in lst:
                if c.contains(self):
                    log_error("Attempting to add a list with me in it")
                    return
            self.children.extend(lst)
        else:
            self.append(lst)
예제 #21
0
def update_modules(module=None):
    ret = False
    conf = Settings.get(plugin_id)
    for mod in conf.get_section('/settings/remote-modules/modules'):
        if module and not mod == module:
            continue
        url = conf.get_string('/settings/remote-modules/modules', mod, '')
        log("Fetching module %s as %s" % (mod, url))
        file = get_target_file(url)
        if not download_module(url, file):
            log_error("Failed to fetch module: %s" % mod)
            continue
        ret = True
    return ret
예제 #22
0
def __main__(args):
    global plugin_id
    # List all namespaces recursivly
    core = Core.get(plugin_id)
    (ret, ns_msgs) = core.simple_exec('CheckWMI', 'wmi', ['--list-all-ns'])
    if len(ns_msgs) == 0:
        log_error("Failed to execute WMI command is CheckWMI enabled?")
    else:
        for ns in ns_msgs[0].splitlines():
            # List all classes in each namespace
            (ret, cls_msgs) = core.simple_exec(
                'any', 'wmi',
                ['--list-classes', '--simple', '--namespace', ns])
            for cls in cls_msgs[0].splitlines():
                log('%s : %s' % (ns, cls))
예제 #23
0
	def do_one_test(self, script, expected = status.OK, message = "Foo Bar", args=[], cleanup=True):
		result = TestResult('%s (%s)'%(script, args))
		(ret, msg, perf) = self.core.simple_query(script, args)
		if cleanup and os.name != 'nt':
			message = message.replace('"', '')
			message = message.replace('$ARG1$', '$')
			message = message.replace('$ARG2$', '$')
			message = message.replace('$ARG3$', '$')

		message = message.replace('\r', '\n')
		message = message.replace('\n\n', '\n')
		msg = msg.replace('\r', '\n')
		msg = msg.replace('\n\n', '\n')

		result.assert_equals(ret, expected, 'Validate return code for %s'%script)
		result.assert_equals(msg, message, 'Validate return message for %s'%script)
		if msg != message:
			diff = difflib.ndiff(msg.splitlines(1), message.splitlines(1))
			for l in diff:
				log_error(l)
		return result
예제 #24
0
	def run(self, arguments = []):
		cases = []
		try:
			parser = ThrowingArgumentParser(prog='nscp')
			parser.add_argument("--script", help="The script to run (sort of ignored)", action='store')
			parser.add_argument("--case", help="Which test case to run", action='append')
			args = parser.parse_args(arguments)
			cases = args.case
		except Exception as e:
			log_error('Failed to parse command line: %s'%e)
			
		result = TestResult('Test result for %d suites'%len(self.suites))
		for suite in self.suites:
			instance = suite.getInstance()
			instance.setup(self.plugin_id, self.prefix)
			suite_result = TestResult('Running suite: %s'%instance.title())
			if cases:
				suite_result.append(instance.run_test(cases))
			else:
				suite_result.append(instance.run_test())
			result.append(suite_result)
			result.add_message(suite_result.is_ok(), 'Result from suite: %s'%instance.title())
			instance.teardown()
		return result
예제 #25
0
파일: test_helper.py 프로젝트: jkells/nscp
 def log(self, prefix="", indent=0):
     if self.status:
         log_debug("%s%s%s" % (prefix, "".rjust(indent, " "), self))
     else:
         log_error("%s%s%s" % (prefix, "".rjust(indent, " "), self))