def set_acknowledgement_on_services(params): """Set acknowledgement on related services""" body = params["body"] live = sites.live() sticky = body["sticky"] notify = body["notify"] persistent = body["persistent"] comment = body["comment"] acknowledge_type = body["acknowledge_type"] if acknowledge_type == "service": description = unquote(body["service_description"]) host_name = body["host_name"] service = Query( [Services.host_name, Services.description, Services.state], And(Services.host_name == host_name, Services.description == description), ).first(live) if not service: raise ProblemException( status=400, title= f"Service {description!r}@{host_name!r} could not be found.", ) if not service.state: raise ProblemException( status=422, title=f"Service {description!r}@{host_name!r} has no problem.", ) acknowledge_service_problem( live, service.host_name, service.description, sticky=sticky, notify=notify, persistent=persistent, user=user.ident, comment=comment, ) elif acknowledge_type == "servicegroup": service_group = body["servicegroup_name"] try: acknowledge_servicegroup_problem( live, service_group, sticky=sticky, notify=notify, persistent=persistent, user=user.ident, comment=comment, ) except ValueError: raise ProblemException( status=400, title="Service group could not be found.", detail=f"Unknown service group: {service_group}", ) elif acknowledge_type == "service_by_query": services = Query( [Services.host_name, Services.description, Services.state], body["query"], ).fetchall(live) if not services: raise ProblemException( status=422, title="No services with problems found.", detail="All queried services are OK.", ) for service in services: if not service.state: continue acknowledge_service_problem( live, service.host_name, service.description, sticky=sticky, notify=notify, persistent=persistent, user=user.ident, comment=comment, ) else: raise ProblemException( status=400, title="Unhandled acknowledge-type.", detail= f"The acknowledge-type {acknowledge_type!r} is not supported.", ) return http.Response(status=204)
def set_acknowledgement_on_services(params): """Set acknowledgement on related services""" body = params['body'] live = sites.live() sticky = body['sticky'] notify = body['notify'] persistent = body['persistent'] comment = body['comment'] acknowledge_type = body['acknowledge_type'] if acknowledge_type == 'service': description = unquote(body['service_description']) host_name = body['host_name'] service = Query( [Services.host_name, Services.description, Services.state], And(Services.host_name == host_name, Services.description == description)).first(live) if not service: raise ProblemException( status=400, title= f'Service {description!r}@{host_name!r} could not be found.', ) if not service.state: raise ProblemException( status=422, title=f'Service {description!r}@{host_name!r} has no problem.', ) acknowledge_service_problem( live, service.host_name, service.description, sticky=sticky, notify=notify, persistent=persistent, user=config.user.ident, comment=comment, ) elif acknowledge_type == 'servicegroup': service_group = body['servicegroup_name'] try: acknowledge_servicegroup_problem( live, service_group, sticky=sticky, notify=notify, persistent=persistent, user=config.user.ident, comment=comment, ) except ValueError: raise ProblemException( status=400, title="Servicegroup could not be found.", detail=f"Unknown servicegroup: {service_group}", ) elif acknowledge_type == 'service_by_query': services = Query( [Services.host_name, Services.description, Services.state], body['query'], ).fetchall(live) if not services: raise ProblemException( status=422, title='No services with problems found.', detail='All queried services are OK.', ) for service in services: if not service.state: continue acknowledge_service_problem( live, service.host_name, service.description, sticky=sticky, notify=notify, persistent=persistent, user=config.user.ident, comment=comment, ) else: raise ProblemException( status=400, title="Unhandled acknowledge-type.", detail= f"The acknowledge-type {acknowledge_type!r} is not supported.", ) return http.Response(status=204)