def show_downtimes(param): """Show all scheduled downtimes""" live = sites.live() sites_to_query = param.get("sites") if sites_to_query: live.only_sites = sites_to_query q = Query( [ Downtimes.id, Downtimes.host_name, Downtimes.service_description, Downtimes.is_service, Downtimes.author, Downtimes.start_time, Downtimes.end_time, Downtimes.recurring, Downtimes.comment, ] ) query_expr = param.get("query") if query_expr is not None: q = q.filter(query_expr) host_name = param.get("host_name") if host_name is not None: q = q.filter(And(Downtimes.host_name.op("=", host_name), Downtimes.is_service.equals(0))) service_description = param.get("service_description") if service_description is not None: q = q.filter(Downtimes.service_description.contains(service_description)) gen_downtimes = q.iterate(live) return _serve_downtimes(gen_downtimes)
def list_hosts(param): """Show hosts of specific condition""" live = sites.live() sites_to_query = param["sites"] if sites_to_query: live.only_sites = sites_to_query q = Query(param["columns"]) query_expr = param.get("query") if query_expr: q = q.filter(query_expr) result = q.iterate(live) return constructors.serve_json( constructors.collection_object( domain_type="host", value=[ constructors.domain_object( domain_type="host", title=f"{entry['name']}", identifier=entry["name"], editable=False, deletable=False, extensions=entry, ) for entry in result ], ) )
def _list_services(param): live = sites.live() q = Query(param["columns"]) host_name = param.get("host_name") if host_name is not None: q = q.filter(Services.host_name == host_name) query_expr = param.get("query") if query_expr: q = q.filter(query_expr) result = q.iterate(live) return constructors.serve_json( constructors.collection_object( domain_type="service", value=[ constructors.domain_object( domain_type="service", title=f"{entry['description']} on {entry['host_name']}", identifier=f"{entry['host_name']}:{entry['description']}", editable=False, deletable=False, extensions=entry, self_link=constructors.link_rel( rel="cmk/show", href=constructors.object_action_href( "host", entry["host_name"], "show_service", query_params=[("service_description", entry["description"])], ), method="get", title=f"Show the service {entry['description']}", ), ) for entry in result ], ) )
def _list_services(param): live = sites.live() q = Query(param['columns']) host_name = param.get('host_name') if host_name is not None: q = q.filter(Services.host_name == host_name) query_expr = param.get('query') if query_expr: q = q.filter(query_expr) result = q.iterate(live) return constructors.serve_json( constructors.collection_object( domain_type='service', value=[ constructors.domain_object( domain_type='service', title=f"{entry['description']} on {entry['host_name']}", identifier=f"{entry['host_name']}:{entry['description']}", editable=False, deletable=False, extensions=entry, self_link=constructors.link_rel( rel='cmk/show', href=constructors.object_action_href( 'host', entry['host_name'], 'show_service', query_params=[('service_description', entry['description'])], ), method='get', title=f"Show the service {entry['description']}", ), ) for entry in result ], ))