Ejemplo n.º 1
0
def do_render_availability(what: AVObjectType, av_rawdata: AVRawData, av_data: AVData,
                           av_mode: AVMode, av_object: AVObjectSpec, avoptions: AVOptions) -> None:
    if av_mode == "timeline":
        render_availability_timelines(what, av_data, avoptions)
    else:
        availability_tables = availability.compute_availability_groups(what, av_data, avoptions)
        render_availability_tables(availability_tables, what, avoptions)

    annotations = availability.load_annotations()
    show_annotations(annotations, av_rawdata, what, avoptions, omit_service=av_object is not None)
Ejemplo n.º 2
0
def do_render_availability(what, av_rawdata, av_data, av_mode, av_object, avoptions):

    if av_mode == "timeline":
        render_availability_timelines(what, av_data, avoptions)
    else:
        availability_tables = availability.compute_availability_groups(what, av_data, avoptions)
        render_availability_tables(availability_tables, what, avoptions)

    annotations = availability.load_annotations()
    show_annotations(annotations, av_rawdata, what, avoptions, omit_service=av_object is not None)
Ejemplo n.º 3
0
def handle_delete_annotations():
    if html.request.var("_delete_annotation"):
        _site_id, _hostname, _service, host_state, service_state, fromtime, \
                untiltime, site_host_svc = _handle_anno_request_vars()

        annotations = availability.load_annotations()
        annotation = availability.find_annotation(annotations, site_host_svc, host_state,
                                                  service_state, fromtime, untiltime)
        if not annotation:
            return

        if not html.confirm(
                _("Are you sure that you want to delete the annotation '%s'?") %
                annotation["text"]):
            return

        availability.delete_annotation(annotations, site_host_svc, host_state, service_state,
                                       fromtime, untiltime)
        availability.save_annotations(annotations)
Ejemplo n.º 4
0
def handle_delete_annotations():
    if html.request.var("_delete_annotation"):
        site_id = html.request.var("anno_site") or ""
        hostname = html.request.var("anno_host")
        service = html.request.var("anno_service") or None
        fromtime = float(html.request.var("anno_from"))
        untiltime = float(html.request.var("anno_until"))
        site_host_svc = (site_id, hostname, service)

        annotations = availability.load_annotations()
        annotation = availability.find_annotation(annotations, site_host_svc, fromtime, untiltime)
        if not annotation:
            return

        if not html.confirm(
                _("Are you sure that you want to delete the annotation '%s'?") %
                annotation["text"]):
            return

        availability.delete_annotation(annotations, site_host_svc, fromtime, untiltime)
        availability.save_annotations(annotations)
Ejemplo n.º 5
0
def edit_annotation():
    site_id = html.request.var("anno_site") or ""
    hostname = html.request.get_str_input_mandatory("anno_host")
    service = html.request.var("anno_service") or None
    fromtime = html.request.get_float_input_mandatory("anno_from")
    untiltime = html.request.get_float_input_mandatory("anno_until")
    site_host_svc = (site_id, hostname, service)

    # Find existing annotation with this specification
    annotations = availability.load_annotations()
    annotation = availability.find_annotation(annotations, site_host_svc,
                                              fromtime, untiltime)

    if annotation:
        value = annotation.copy()
    else:
        value = {
            "from": fromtime,
            "until": untiltime,
            "text": "",
        }

    value["host"] = hostname
    value["service"] = service
    value["site"] = site_id

    if html.check_transaction():
        try:
            vs = _vs_annotation()
            value = vs.from_html_vars("_editanno")
            vs.validate_value(value, "_editanno")

            site_host_svc = (value["site"], value["host"], value["service"])
            del value["site"]
            del value["host"]
            value["date"] = time.time()
            value["author"] = config.user.id
            availability.update_annotations(site_host_svc,
                                            value,
                                            replace_existing=annotation)
            html.request.del_var("filled_in")
            return False
        except MKUserError as e:
            html.user_error(e)

    title = _("Edit annotation of ") + hostname
    if service:
        title += "/" + service

    html.body_start(title)
    html.top_heading(title)

    html.begin_context_buttons()
    html.context_button(_("Abort"), html.makeuri([("anno_host", "")]), "abort")
    html.end_context_buttons()

    html.begin_form("editanno", method="GET")
    _vs_annotation().render_input_as_form("_editanno", value)

    html.button("save", _("Save"))

    html.hidden_fields()
    html.end_form()

    html.bottom_footer()
    html.body_end()
    return True