alignak_backend_client/backend_client.py
def initialize(self):
        # pylint: disable=attribute-defined-outside-init
        """Login on backend with username and password

        :return: None
        """
        try:
            logger.info("Authenticating...")
            self.backend = Backend(self.backend_url)
            self.backend.login(self.username, self.password)
        except BackendException as exp:  # pragma: no cover, should never happen
            logger.exception("Exception: %s", exp)
            logger.error("Response: %s", exp.response)

        if self.backend.token is None:
            print("Access denied!")
            print("~~~~~~~~~~~~~~~~~~~~~~~~~~")
            print("Exiting with error code: 1")
            exit(1)

        logger.info("Authenticated.")

        # Logged-in user and default realm
        users = self.backend.get_all('user', {'where': json.dumps({'name': self.username})})
        self.logged_in_user = users['_items'][0]
        self.default_realm = self.logged_in_user['_realm']

        # Main realm
        self.realm_all = None
        realms = self.backend.get_all('realm')
        for r in realms['_items']:
            if r['name'] == 'All' and r['_level'] == 0:
                self.realm_all = r['_id']
                logger.info("Found realm 'All': %s", self.realm_all)
            if r['_id'] == self.default_realm:
                logger.info("Found logged-in user realm: %s", r['name'])

        # Default timeperiods
        self.tp_always = None
        self.tp_never = None
        timeperiods = self.backend.get_all('timeperiod')
        for tp in timeperiods['_items']:
            if tp['name'] == '24x7':
                self.tp_always = tp['_id']
                logger.info("Found TP '24x7': %s", self.tp_always)
            if tp['name'].lower() == 'none' or tp['name'].lower() == 'never':
                self.tp_never = tp['_id']
                logger.info("Found TP 'Never': %s", self.tp_never)
def initialize(self):
        # pylint: disable=attribute-defined-outside-init
        try:
            logger.info("Authenticating...")
            self.backend = Backend(self.backend_url)
            self.backend.login(self.username, self.password)
        except BackendException as exp:  # pragma: no cover, should never happen
            logger.exception("Exception: %s", exp)
            logger.error("Response: %s", exp.response)

        if self.backend.token is None:
            print("Access denied!")
            print("~~~~~~~~~~~~~~~~~~~~~~~~~~")
            print("Exiting with error code: 1")
            exit(1)

        logger.info("Authenticated.")

        # Logged-in user and default realm
        users = self.backend.get_all('user', {'where': json.dumps({'name': self.username})})
        self.logged_in_user = users['_items'][0]
        self.default_realm = self.logged_in_user['_realm']

        # Main realm
        self.realm_all = None
        realms = self.backend.get_all('realm')
        for r in realms['_items']:
            if r['name'] == 'All' and r['_level'] == 0:
                self.realm_all = r['_id']
                logger.info("Found realm 'All': %s", self.realm_all)
            if r['_id'] == self.default_realm:
                logger.info("Found logged-in user realm: %s", r['name'])

        # Default timeperiods
        self.tp_always = None
        self.tp_never = None
        timeperiods = self.backend.get_all('timeperiod')
        for tp in timeperiods['_items']:
            if tp['name'] == '24x7':
                self.tp_always = tp['_id']
                logger.info("Found TP '24x7': %s", self.tp_always)
            if tp['name'].lower() == 'none' or tp['name'].lower() == 'never':
                self.tp_never = tp['_id']
                logger.info("Found TP 'Never': %s", self.tp_never)
def initialize ( self ) : # pylint: disable=attribute-defined-outside-init try : logger . info ( "Authenticating..." ) self . backend = Backend ( self . backend_url ) self . backend . login ( self . username , self . password ) except BackendException as exp : # pragma: no cover, should never happen logger . exception ( "Exception: %s" , exp ) logger . error ( "Response: %s" , exp . response ) if self . backend . token is None : print ( "Access denied!" ) print ( "~~~~~~~~~~~~~~~~~~~~~~~~~~" ) print ( "Exiting with error code: 1" ) exit ( 1 ) logger . info ( "Authenticated." ) # Logged-in user and default realm users = self . backend . get_all ( 'user' , { 'where' : json . dumps ( { 'name' : self . username } ) } ) self . logged_in_user = users [ '_items' ] [ 0 ] self . default_realm = self . logged_in_user [ '_realm' ] # Main realm self . realm_all = None realms = self . backend . get_all ( 'realm' ) for r in realms [ '_items' ] : if r [ 'name' ] == 'All' and r [ '_level' ] == 0 : self . realm_all = r [ '_id' ] logger . info ( "Found realm 'All': %s" , self . realm_all ) if r [ '_id' ] == self . default_realm : logger . info ( "Found logged-in user realm: %s" , r [ 'name' ] ) # Default timeperiods self . tp_always = None self . tp_never = None timeperiods = self . backend . get_all ( 'timeperiod' ) for tp in timeperiods [ '_items' ] : if tp [ 'name' ] == '24x7' : self . tp_always = tp [ '_id' ] logger . info ( "Found TP '24x7': %s" , self . tp_always ) if tp [ 'name' ] . lower ( ) == 'none' or tp [ 'name' ] . lower ( ) == 'never' : self . tp_never = tp [ '_id' ] logger . info ( "Found TP 'Never': %s" , self . tp_never )
Login on backend with username and password

        :return: None
Login on backend with username and password