Esempio n. 1
0
def get_all_hosts_datatable():
    '''Get all hosts'''
    data = {
        "columns": [
            { "data": "hostname", "title": "Hostname" },
            { "data": "ip_address", "title": "IP Address" },
            { "data": "last_poll", "title": "Last Poll" },
            { "data": "status", "title": "Status" }
        ],
        "data": Schemas.hosts(many=True).dump(Hosts.query.all())
    }
    return json.dumps(data)
Esempio n. 2
0
def get_user(username):
    """Get user based on username

    Args:
        username (str): Username

    Returns:
        dict
    """
    if database_configured():
        user_data = Users.query.filter_by(username=username).first()
        return Schemas.users(many=False).dump(user_data)
    else:
        return None
Esempio n. 3
0
def _host_status_alerts_threaded():
    with app.app_context():
        alerts_enabled = json.loads(get_alerts_enabled())['alerts_enabled']
        smtp_configured = json.loads(get_smtp_configured())['smtp_configured']
        alerts = HostAlerts.query.filter_by(alert_cleared=False).all()

        for alert in alerts:
            alert.alert_cleared = True

        if smtp_configured and alerts_enabled:
            pool = ThreadPool(config['Max_Threads'])
            threads = []

            message = ''
            for alert in alerts:
                threads.append(
                    pool.apply_async(_get_alert_status_message, (alert,))
                )

            pool.close()
            pool.join()

            for thread in threads:
                message += thread.get()

            if message:
                recipients = ';'.join(x['email'] for x in Schemas.users(many=True).dump(Users.query.filter_by(alerts_enabled=True)))
                try:
                    send_smtp_message(
                        recipient=recipients,
                        subject='IPMON - Host Status Change Alert',
                        message=message
                    )
                except Exception as exc:
                    log.error('Failed to send host status change alert email: {}'.format(exc))

        db.session.commit()
Esempio n. 4
0
def get_active_theme():
    '''Get active theme'''
    return json.dumps(Schemas.web_themes(many=False).dump(WebThemes.query.filter_by(active=True).first()))
Esempio n. 5
0
def get_web_themes():
    '''Get all web themese'''
    return json.dumps(Schemas.web_themes(many=True).dump(WebThemes.query.all()))
Esempio n. 6
0
def get_smtp_config():
    '''Get SMTP config'''
    return json.dumps(Schemas.smtp_config().dump(SmtpServer.query.first()))
Esempio n. 7
0
def get_alerts_enabled():
    '''Get whether alerts are enabled or not'''
    status = Schemas.users(many=False).dump(Users.query.first())['alerts_enabled']
    return json.dumps({'alerts_enabled': status})
Esempio n. 8
0
def get_poll_history(host_id):
    '''Get poll history for a single host'''
    return json.dumps(Schemas.poll_history(many=True).dump(PollHistory.query.filter_by(host_id=host_id)))
Esempio n. 9
0
def get_polling_config():
    '''Get polling config'''
    return json.dumps(Schemas.polling_config().dump(Polling.query.filter_by(id=1).first()))
Esempio n. 10
0
def get_new_host_alerts():
    '''Get new host alerts'''
    return json.dumps(Schemas.host_alerts(many=True).dump(HostAlerts.query.filter_by(alert_cleared=False)))
Esempio n. 11
0
def get_all_host_alerts():
    '''Get all host alerts'''
    return json.dumps(Schemas.host_alerts(many=True).dump(HostAlerts.query.join(Hosts).all()))
Esempio n. 12
0
def get_host(_id):
    '''Get host by ID'''
    return json.dumps(Schemas.hosts(many=False).dump(Hosts.query.filter_by(id=_id).first()))