def get_information(self): mail = self.config.get('test', 'mail') if mail: mail_actions = {ACTIONS.EDIT, ACTIONS.DELETE} else: mail_actions = {ACTIONS.EDIT} return { 'id': info_property(self.config.get('test', 'id')), 'uid': info_property(self.config.get('test', 'uid')), 'address': info_property(self.config.get('test', 'address')), 'mail': info_property(self.config.get('test', 'mail'), actions=mail_actions), 'status': info_property("OK", STATUS_COLORS.GOOD), 'ip': info_property(self.config.get('test', 'ip'), STATUS_COLORS.INFO), 'mac': info_property(self.config.get('test', 'mac'), actions={ACTIONS.EDIT}), 'hostname': info_property(self.config.get('test', 'hostname')), 'hostalias': info_property(self.config.get('test', 'hostalias')) }
def get_information(self): userData = do_api_call(str(self.id)) ips = ", ".join([h['ip'] for h in userData['hosts'] if h['ip'] is not None]) macs = ", ".join([h['mac'] for h in userData['hosts'] if h['mac'] is not None]) hosts = ", ".join([h['hostname'] for h in userData['hosts'] if h['hostname'] is not None]) aliases = ", ".join([h['alias'] for h in userData['hosts'] if h['alias'] is not None]) return { 'id': info_property(userData['id']), 'uid': info_property(userData['login']), 'address': info_property(userData['address']), 'mail': info_property(userData['mail']), 'status': info_property(userData['status'], STATUS_COLORS.GOOD), 'ip': info_property(ips, STATUS_COLORS.INFO), 'mac': info_property(macs), 'hostname': info_property(hosts), 'hostalias': info_property(aliases) }
def get_information(self): """Executes select query for the username and returns a prepared dict. * Dormitory IDs in Mysql are from 1-11, so we map to 0-10 with "x-1". Returns "-1" if a query result was empty (None), else returns the prepared dict. """ userinfo = {} user = sql_query( "SELECT nutzer_id, wheim_id, etage, zimmernr, status " "FROM nutzer " "WHERE unix_account = %s", (self.uid,) ).fetchone() if not user: raise DBQueryEmpty mysql_id = user['nutzer_id'] userinfo.update( id=info_property( "{}-{}".format(mysql_id, calculate_userid_checksum(mysql_id))), address=info_property("{0} / {1} {2}".format( DORMITORIES[user['wheim_id'] - 1], user['etage'], user['zimmernr'] )), # todo use more colors (yellow for finances etc.) status=info_property(status_string_from_id(user['status']), status_color=(STATUS_COLORS.GOOD if user['status'] is 1 else None)), ) computer = sql_query( "SELECT c_etheraddr, c_ip, c_hname, c_alias " "FROM computer " "WHERE nutzer_id = %s", (user['nutzer_id']) ).fetchone() if not computer: raise DBQueryEmpty userinfo.update( ip=info_property(computer['c_ip']), mail=info_property(self.mail, actions={ACTIONS.EDIT, ACTIONS.DELETE}), mac=info_property(computer['c_etheraddr'].upper(), actions={ACTIONS.EDIT}), # todo figure out where that's being used hostname=info_property(computer['c_hname']), hostalias=info_property(computer['c_alias']) ) try: if user_has_mysql_db(self.uid): user_db_prop = info_property( gettext("Aktiviert"), status_color=STATUS_COLORS.GOOD, actions={ACTIONS.EDIT} ) else: user_db_prop = info_property( gettext("Nicht aktiviert"), status_color=STATUS_COLORS.INFO, actions={ACTIONS.EDIT} ) except OperationalError: logger.critical("User db unreachable") user_db_prop = info_property(gettext( "Datenbank nicht erreichbar")) finally: userinfo.update(userdb=user_db_prop) return userinfo