Exemplo n.º 1
0
    def __init__(self, url=None, username=None, password=None, check_ssl=True):
        Webservice.getInstance(url, username, password, check_ssl)

        self.hosts = Hosts()
        self.services = Service()
        self.pollers = Pollers()
        self.hostgroups = HostGroups()
        self.hosttemplates = HostTemplates()
        self.commands = Commands()
        self.resourcecfgs = ResourceCFGs()
Exemplo n.º 2
0
 def __init__(self, properties):
     self.webservice = Webservice.getInstance()
     self.__clapi_action = 'CMD'
     self.id = properties.get('id')
     self.name = properties.get('name')
     self.line = self._build_command_line(properties.get('line'))
     self.type = properties.get('type')
Exemplo n.º 3
0
 def __init__(self, properties):
     self.webservice = Webservice.getInstance()
     self.__clapi_action = 'RESOURCECFG'
     self.id = properties.get('id')
     self.instance = properties.get('instance')
     self.name = properties.get('name')
     self.activate = properties.get('activate')
     self.value = properties.get('value')
Exemplo n.º 4
0
 def __init__(self, properties):
     self.webservice = Webservice.getInstance()
     self.__clapi_action = 'INSTANCE'
     self.id = properties['id']
     self.bin = properties['bin']
     self.activate = properties['activate']
     self.init_script = properties['init script']
     self.ipaddress = properties['ip address']
     self.localhost = properties['localhost']
     self.name = properties['name']
     self.ssh_port = properties['ssh port']
     self.stats_bin = properties['stats bin']
     self.status = properties['status']
     self.pollerHost = dict()
    def test_connection(self):
        url = "http://api.domain.tld/centreon"
        username = "******"
        password = "******"
        mytoken = "NTc1MDU3MGE3M2JiODIuMjA4OTA2OTc="
        wsresponses = '{"authToken": "NTc1MDU3MGE3M2JiODIuMjA4OTA2OTc="}'
        responses.add(
            responses.POST,
            'http://api.domain.tld/centreon/api/index.php?action=authenticate',
            body=wsresponses, status=200, content_type='application/json')

        myconn = Webservice.getInstance(url, username, password)
        myconn.auth()
        assert mytoken == myconn.auth_token
Exemplo n.º 6
0
 def __init__(self, properties):
     self.webservice = Webservice.getInstance()
     self.__clapi_action = 'HOST'
     self.id = properties.get('id')
     self.name = properties.get('name')
     self.activate = properties.get('activate')
     self.address = properties.get('address')
     self.alias = properties.get('alias')
     self.macros = dict()
     self.templates = dict()
     self.parents = dict()
     self.hostgroups = dict()
     self.contactgroups = dict()
     self.contacts = dict()
     self.state = properties.get('state')
Exemplo n.º 7
0
 def __init__(self):
     self.webservice = Webservice.getInstance()
Exemplo n.º 8
0
def applyRudderMonitoringConfigurations(conf):
    centreon_hosts = Host()
    register = configparser.ConfigParser()
    register.read(registerFile)

    for dir in next(os.walk('/var/rudder/shared-files/root/files'))[1]:
        try:
            confcsv = csv.reader(
                open('/var/rudder/shared-files/root/files/' + dir +
                     '/rudder_monitoring.csv'))
        except:
            print(
                '[!] Node ' + dir +
                ' has no rudder monitoring config file, considering it empty...'
            )
            confcsv = []

        if not any(h['name'] == dir for h in centreon_hosts.list()['result']):
            print('[!] Node ' + dir +
                  ' is not registered in Centreon, skipping...')
            continue

        print('[ ] Applying conf to node ' + dir + '...')
        csvTmpList = []
        csvMacroKeyList = []
        for r in confcsv:
            if (r[0] == 'template'):
                csvTmpList.append(r[1])
                if not any(t['name'] == r[1]
                           for t in centreon_hosts.gettemplate(dir)['result']):
                    try:
                        centreon_hosts.addtemplate(dir, r[1])
                        centreon_hosts.applytemplate(dir)
                        registerTemplate(dir, r[1], register)
                    except HTTPError:
                        print('[!] Centreon API error, check if template ' +
                              r[1] + ' exists')
                else:
                    print('[ ] Template ' + r[1] +
                          ' already applied to node ' + dir)
                    registerTemplate(dir, r[1], register)
            elif (r[0] == 'param'):
                csvMacroKeyList.append(r[1])
                centreon_hosts.setmacro(dir, r[1], ''.join(r[2:]))
                registerMacro(dir, r[1], ''.join(r[2:]), register)
            else:
                print('[!] Incorrect config parameter type ' + r[0] +
                      ', skipping...')

        for t in centreon_hosts.gettemplate(dir)['result']:
            if not any(t['name'] == n
                       for n in csvTmpList) and templateWasRegistered(
                           dir, t['name'], register):
                unregisterTemplate(dir, t['name'], register)
                centreon_hosts.deletetemplate(dir, t['name'])

        for mk in centreon_hosts.getmacro(dir)['result']:
            if not any(mk['macro name'] == n
                       for n in csvMacroKeyList) and macroWasRegistered(
                           dir, mk['macro name'], register):
                unregisterMacro(dir, mk['macro name'], register)
                centreon_hosts.deletemacro(dir, mk['macro name'])

        #This ensures we get no duplicates in register in case we have to re-add an already registered
        #register[dir]['templates'] = ','.join(list(set(register[dir]['templates'].split(','))))

    register.write(open(registerFile, 'w'))
    print('[ ] Reloading Centreon poller config, restarting poller...')
    Webservice.getInstance().restart_poller(conf['CENTREON']['centreonPoller'])
    print('[+] Done')
Exemplo n.º 9
0
    register.write(open(registerFile, 'w'))
    print('[ ] Reloading Centreon poller config, restarting poller...')
    Webservice.getInstance().restart_poller(conf['CENTREON']['centreonPoller'])
    print('[+] Done')


if __name__ == '__main__':
    args = docopt(__doc__)
    conf = configparser.ConfigParser()
    conf.read(confFile)
    urllib3.disable_warnings(urllib3.exceptions.InsecureRequestWarning)

    try:
        WSInstance = Webservice.getInstance(
            conf['CENTREON']['centreonWebserviceURL'],
            conf['CENTREON']['username'], conf['CENTREON']['password'])
        WSInstance.auth()
    except HTTPError:
        print(
            "[!] Unable to connect to Centreon webservice. Check centreon.conf ?"
        )
        sys.exit(1)

    if (args['pull']):
        updateNodesJSON()
    elif (args['push']):
        updateCentreonHosts(conf['CENTREON']['centreonPoller'])
    elif (args['update']):
        updateNodesJSON()
        updateCentreonHosts(conf['CENTREON']['centreonPoller'])
Exemplo n.º 10
0
 def __init__(self):
     """
     Constructor
     """
     self.webservice = Webservice.getInstance()
Exemplo n.º 11
0
 def auth(self):
     ws = Webservice.getInstance()
     ws.auth()
     return ws
Exemplo n.º 12
0
 def __init__(self):
     self.webservice = Webservice.getInstance()
     self.__clapi_action = ""
Exemplo n.º 13
0
 def __init__(self):
     """
     Constructor
     """
     self.webservice = Webservice.getInstance()
     self.clapi_object = 'HTPL'
Exemplo n.º 14
0
 def __init__(self):
     self.webservice = Webservice.getInstance()
     self.clapi_object = 'SERVICE'