import time from alerta.app import app from alerta.app.database import Mongo LOG = app.logger db = Mongo().get_db() class Gauge(object): def __init__(self, group, name, title=None, description=None): self.group = group self.name = name self.title = title self.description = description def set(self, value): db.metrics.update_one({ "group": self.group, "name": self.name }, { '$set': { "group": self.group, "name": self.name, "title": self.title, "description": self.description, "value": value, "type": "gauge"
import time from alerta.app import app from alerta.app.database import Mongo LOG = app.logger mongo = Mongo() db = mongo.db class Gauge(object): def __init__(self, group, name, title=None, description=None): self.group = group self.name = name self.title = title self.description = description def set(self, value): db.metrics.update({ "group": self.group, "name": self.name }, { "group": self.group, "name": self.name, "title": self.title, "description": self.description, "value": value, "type": "gauge"
logfile_handler = RotatingFileHandler(app.config['LOG_FILE'], maxBytes=100000, backupCount=2) logfile_handler.setLevel(logging.DEBUG) logfile_handler.setFormatter(logging.Formatter(LOG_FORMAT)) for logger in loggers: logger.addHandler(logfile_handler) # Runtime config check if app.config['CUSTOMER_VIEWS'] and not app.config['AUTH_REQUIRED']: raise RuntimeError('Must enable authentication to use customer views') if app.config['CUSTOMER_VIEWS'] and not app.config['ADMIN_USERS']: raise RuntimeError('Customer views is enabled but there are no admin users') cors = CORS(app) from alerta.app.database import Mongo db = Mongo() if sys.version_info[0] == 2: import views import webhooks.views import oembed.views import management.views import auth else: from .views import * from .webhooks.views import * from .oembed.views import * from .management.views import * from .auth import *
#!/usr/bin/env python import datetime from alerta.app.database import Mongo data = { "user": "******", "key": "demo-key", "text": "demo key", "expireTime": datetime.datetime.utcnow() + datetime.timedelta(365), "count": 0, "lastUsedTime": None } Mongo().db.keys.insert(data)