Beispiel #1
0
 def test_run_command_file_not_found(self):
     command = '/bin/doesnotexist'
     expected_msg = '\* Could not run command \(return code= %s\)\n' % 127
     expected_msg += '\* Error was:\n.*: %s: (not found|No such file or directory)\n' % command
     expected_msg += '\* Command was:\n%s\n' % command
     expected_msg += '\* Output was:\n\n'
     expected_msg += 'Check if y/our path is correct: %s' % os.getenv('PATH')
     with self.assertRaisesRegexp(utils.PynagError, expected_msg):
         utils.runCommand(command, raise_error_on_fail=True)
Beispiel #2
0
 def test_run_command_file_not_found(self):
     command = '/bin/doesnotexist'
     expected_msg = '\* Could not run command \(return code= %s\)\n' % 127
     expected_msg += '\* Error was:\n.*: %s: (not found|No such file or directory)\n' % command
     expected_msg += '\* Command was:\n%s\n' % command
     expected_msg += '\* Output was:\n\n'
     expected_msg += 'Check if y/our path is correct: %s' % os.getenv(
         'PATH')
     with self.assertRaisesRegexp(utils.PynagError, expected_msg):
         utils.runCommand(command, raise_error_on_fail=True)
Beispiel #3
0
def verify_configuration():
    """ Verifies nagios configuration and returns the output of nagios -v nagios.cfg
    """
    binary = adagios.settings.nagios_binary
    config = adagios.settings.nagios_config
    command = "%s -v '%s'" % (binary, config)
    code, stdout, stderr = Utils.runCommand(command)

    result = {}
    result['return_code'] = code
    result['output'] = stdout
    result['errors'] = stderr

    return result

    total_errors = 0
    total_warnings = 0

    for line in stdout.splitlines():
        output = {}
        output['tags'] = tags = []
        output['content'] = line
        if line.lower().startswith('warning'):
            tags.append('warning')
            total_warnings += 1
            print line
        if line.lower().startswith('error'):
            tags.append('error')
            total_errors += 1
        result['output'].append(output)
        result['error_count'] = total_errors
        result['warning_count'] = total_warnings
    return result
Beispiel #4
0
def verify_configuration():
    """ Verifies nagios configuration and returns the output of nagios -v nagios.cfg
    """
    binary = adagios.settings.nagios_binary
    config = adagios.settings.nagios_config
    command = "%s -v '%s'" % (binary, config)
    code, stdout, stderr = Utils.runCommand(command)

    result = {}
    result['return_code'] = code
    result['output'] = stdout
    result['errors'] = stderr

    return result

    total_errors = 0
    total_warnings = 0

    for line in stdout.splitlines():
        output = {}
        output['tags'] = tags = []
        output['content'] = line
        if line.lower().startswith('warning'):
            tags.append('warning')
            total_warnings += 1
        if line.lower().startswith('error'):
            tags.append('error')
            total_errors += 1
        result['output'].append(output)
        result['error_count'] = total_errors
        result['warning_count'] = total_warnings
    return result
Beispiel #5
0
def restart_monitoring():
	global Conf
	global Model

	try:
		res = Utils.runCommand(Conf.service + ' restart', raise_error_on_fail=True)
		push_progress('success', 'Relance du logiciel de supervision', 40)
		time.sleep(1)
		push_progress('end', 'Synchronization complete', 100)
	except Exception, e:
		push_progress('failed', 'Echec du redémarrage du logiciel de supervision', 40)
#		push_progress('end', 'end', 100)
		raise e
Beispiel #6
0
def verify_configuration():
    """ Verifies nagios configuration and returns the output of nagios -v nagios.cfg
    """
    binary = adagios.settings.nagios_binary
    config = adagios.settings.nagios_config
    command = "%s -v '%s'" % (binary, config)
    code, stdout, stderr = Utils.runCommand(command)

    result = {}
    result['return_code'] = code
    result['output'] = stdout
    result['errors'] = stderr

    return result
Beispiel #7
0
def verify_configuration():
    """ Verifies nagios configuration and returns the output of nagios -v nagios.cfg
    """
    binary = adagios.settings.nagios_binary
    config = adagios.settings.nagios_config
    command = "%s -v '%s'" % (binary, config)
    code, stdout, stderr = Utils.runCommand(command)

    result = {}
    result['return_code'] = code
    result['output'] = stdout
    result['errors'] = stderr

    return result
Beispiel #8
0
def pre_flight_check():

	#########
	## @ToDo
	## Reprendre le confPath et binPath du fichier de conf de l'agent
	#########

	try:
		res = Utils.runCommand('/usr/local/shinken/bin/shinken-arbiter -v -c /usr/local/shinken/etc/nagios.cfg -c /usr/local/shinken/etc/shinken-specific.cfg', raise_error_on_fail=True)
		push_progress('success', 'Vérification de la nouvelle configuration', 30)
		restart_monitoring()
	except Exception, e:
		push_progress('failed', 'Nouvelle configuration de supervision incorrecte', 30)
		push_progress('end', 'end', 100)
		raise e