Ejemplo n.º 1
0
 async def delete(self) -> None:
     for _ in self.iter_monitors():
         raise errors.IrisettError(
             'can\'t remove active monitor def that is in use')
     del self.manager.monitor_defs[self.id]
     self.tmpl_cache.flush_all()
     await remove_monitor_def_from_db(self.manager.dbcon, self.id)
Ejemplo n.º 2
0
def configure_logging(logtype: str, logfilename: Optional[str]=None, debug_logging: bool=False,
                      rotate_length: int=1000000, max_rotated_files: int=250) -> None:
    global logger
    level = logging.INFO
    if debug_logging:
        level = logging.DEBUG
    if logtype not in ['stdout', 'syslog', 'file']:
        raise errors.IrisettError('invalid logtype name %s' % logtype)
    if rotate_length is None:
        rotate_length = 1000000
    if max_rotated_files is None:
        max_rotated_files = 250
    logger = logging.getLogger('irisett')
    logger.setLevel(level)

    if logtype == 'stdout':
        handler = logging.StreamHandler()  # type: Any
        handler.setLevel(level)
        formatter = logging.Formatter('%(asctime)s - %(levelname)s - %(message)s')
    elif logtype == 'syslog':
        handler = logging.handlers.SysLogHandler(address='/dev/log')
        handler.setLevel(level)
        formatter = logging.Formatter('%(name)s - %(levelname)s - %(message)s')
    else:  # == file
        logfilename = cast(str, logfilename)
        logpath = os.path.split(logfilename)[0]
        if not os.path.exists(logpath):
            os.makedirs(logpath)
        handler = logging.handlers.RotatingFileHandler(logfilename, maxBytes=rotate_length,
                                                       backupCount=max_rotated_files)
        handler.setLevel(level)
        formatter = logging.Formatter('%(asctime)s - %(levelname)s - %(message)s')
    handler.setFormatter(formatter)
    logger.addHandler(handler)
Ejemplo n.º 3
0
 async def _run(cur: Cursor) -> None:
     for key, value in data.items():
         if key not in ['name', 'active']:
             raise errors.IrisettError('invalid contact key %s' % key)
         q = """update contact_groups set %s=%%s where id=%%s""" % key
         q_args = (value, contact_group_id)
         await cur.execute(q, q_args)
Ejemplo n.º 4
0
 async def _run(cur: Cursor) -> None:
     for key, value in data.items():
         if key not in ['parent_id', 'name']:
             raise errors.IrisettError('invalid monitor_group key %s' % key)
         if key == 'parent_id' and value:
             if monitor_group_id == int(value):
                 raise errors.InvalidArguments(
                     'monitor group can\'t be its own parent')
             if not await monitor_group_exists(dbcon, value):
                 raise errors.InvalidArguments(
                     'parent monitor group does not exist')
         q = """update monitor_groups set %s=%%s where id=%%s""" % key
         q_args = (value, monitor_group_id)
         await cur.execute(q, q_args)