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)
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
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()
def get_active_theme(): '''Get active theme''' return json.dumps(Schemas.web_themes(many=False).dump(WebThemes.query.filter_by(active=True).first()))
def get_web_themes(): '''Get all web themese''' return json.dumps(Schemas.web_themes(many=True).dump(WebThemes.query.all()))
def get_smtp_config(): '''Get SMTP config''' return json.dumps(Schemas.smtp_config().dump(SmtpServer.query.first()))
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})
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)))
def get_polling_config(): '''Get polling config''' return json.dumps(Schemas.polling_config().dump(Polling.query.filter_by(id=1).first()))
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)))
def get_all_host_alerts(): '''Get all host alerts''' return json.dumps(Schemas.host_alerts(many=True).dump(HostAlerts.query.join(Hosts).all()))
def get_host(_id): '''Get host by ID''' return json.dumps(Schemas.hosts(many=False).dump(Hosts.query.filter_by(id=_id).first()))