Ejemplo n.º 1
0
def create_alert_event(
        name, status, fingerprint, confirm, confirm_user, ):
    alert_event = AlertEvent(
        name, status, fingerprint, confirm, confirm_user,)
    with session_maker() as s:
        s.add(alert_event)
        s.commit()
        s.refresh(alert_event)
    return alert_event
Ejemplo n.º 2
0
def query_all_host(_phy=True):
    with session_maker() as session:
        res = []
        for host in session.query(Host):
            if _phy == True:
                if host.node_type in PHYSICAL_HOST_JOB:
                    res.append(host)
            else:
                res.append(host)

    return res
Ejemplo n.º 3
0
def create_alert_rule(
        name, group, expr, for_, costom_label, severity, scope, summary, desc):
    rule = AlertRule(
        name=name,
        group=group,
        expr=expr,
        for_=for_,
        costom_label=None if not costom_label else costom_label,
        severity=severity,
        scope=None if not scope else scope,
        summary=summary,
        desc=desc
    )
    with session_maker() as s:
        s.add(rule)
        s.commit()
        s.refresh(rule)
    return rule
Ejemplo n.º 4
0
def create_host(ip, node_type, exporter_port, interval, physical, costom_label,
                desc, ssh_auth_t, ssh_auth, ssh_port, bmc_url):
    host = Host(ip=ip,
                node_type=node_type,
                state=1,
                exporter_port=exporter_port,
                physical=physical,
                costom_label=costom_label,
                description=desc,
                interval=interval,
                ssh_auth=ssh_auth,
                ssh_auth_type=ssh_auth_t,
                ssh_port=ssh_port,
                bmc_url=bmc_url)
    with session_maker() as s:
        s.add(host)
        s.commit()
        s.refresh(host)
    return host
Ejemplo n.º 5
0
def query_all_alert_event():
    with session_maker() as session:
        return [alert_event for alert_event in session.query(AlertEvent)]
Ejemplo n.º 6
0
def confirm_alert_event_by_fingerprint(fingerprint, confirmer):
    with session_maker() as session:
        event = session.query(AlertEvent).filter(AlertEvent.fingerprint == fingerprint).first()
        event.confirm = True
        event.confirmer = confirmer
        session.commit()
Ejemplo n.º 7
0
def query_alert_event_by_fingerprint(fingerprint):
    with session_maker() as session:
        return session.query(AlertEvent).filter(AlertEvent.fingerprint == fingerprint).first()
Ejemplo n.º 8
0
def query_alert_event_by_name(name):
    with session_maker() as session:
        return session.query(AlertEvent).filter(AlertEvent.name == name).first()
Ejemplo n.º 9
0
def delete_alert_event(name):
    with session_maker() as session:
        alert_event = session.query(AlertEvent).filter(AlertEvent.name == name).first()
    return alert_event
Ejemplo n.º 10
0
def query_host(ip):
    with session_maker() as session:
        return session.query(Host).filter(Host.ip == ip).first()
Ejemplo n.º 11
0
def update_host(ip, state):
    with session_maker() as session:
        host = session.query(Host).filter(Host.ip == ip).first()
        host.state = state
        session.commit()
    return host
Ejemplo n.º 12
0
def delete_host(ip, node_type):
    with session_maker() as session:
        host = session.query(Host).filter(Host.ip == ip,
                                          Host.node_type == node_type).first()
    return host
Ejemplo n.º 13
0
def query_all_alert_rule():
    with session_maker() as session:
        return [rule for rule in session.query(AlertRule)]
Ejemplo n.º 14
0
def query_alert_rule(name):
    with session_maker() as session:
        return session.query(AlertRule).filter(AlertRule.name == name).first()
Ejemplo n.º 15
0
def delete_alert_rule(name):
    with session_maker() as session:
        rule = session.query(AlertRule).filter(AlertRule.name == name).first()
    return rule