def _tag_choices_valuespec(self): # We want the compact tuple style visualization which is not # supported by the Dictionary valuespec. Transform! return Transform( ListOf( Tuple( elements=[ Transform( TextInput( title=_("Tag ID"), size=40, regex="^[-a-z0-9A-Z_]*$", regex_error=_( "Invalid tag ID. Only the characters a-z, A-Z, " "0-9, _ and - are allowed." ), allow_empty=True, ), forth=lambda x: "" if x is None else x, back=lambda x: None if not x else x, ), TextInput( title=_("Title") + "*", allow_empty=False, size=60, ), Foldable( ListChoice( title=_("Auxiliary tags"), choices=self._effective_config.aux_tag_list.get_choices(), ), ), ], show_titles=True, orientation="horizontal", ), add_label=_("Add tag choice"), sort_by=1, # sort by description help=_( "The first choice of a tag group will be its default value. " "If a tag group has only one choice, it will be displayed " "as a checkbox and set or not set the only tag. If it has " "more choices you may leave at most one tag id empty. A host " "with that choice will not get any tag of this group.<br><br>" "The tag ID must contain only of letters, digits and " "underscores.<br><br><b>Renaming tags ID:</b> if you want " "to rename the ID of a tag, then please make sure that you do not " "change its title at the same time! Otherwise WATO will not " "be able to detect the renaming and cannot exchange the tags " "in all folders, hosts and rules accordingly." ), ), forth=lambda x: [(c["id"], c["title"], c["aux_tags"]) for c in x], back=lambda x: [dict(zip(["id", "title", "aux_tags"], c)) for c in x], )
def get_vs_flexible_notifications(): # Make sure, that list is not trivially false def validate_only_services(value, varprefix): for s in value: if s and s[0] != '!': return raise MKUserError(varprefix + "_0", _("The list of services will never match")) return CascadingDropdown( title=_("Notification Method"), choices=[ ("email", _("Plain Text Email (using configured templates)")), ( "flexible", _("Flexible Custom Notifications"), ListOf( Foldable( Dictionary( optional_keys=[ "service_blacklist", "only_hosts", "only_services", "escalation", "match_sl" ], columns=1, elements=[ ( "plugin", DropdownChoice( title=_("Notification Plugin"), choices=notification_script_choices, default_value="mail", ), ), ("parameters", ListOfStrings( title=_("Plugin Arguments"), help= _("You can specify arguments to the notification plugin here. " "Please refer to the documentation about the plugin for what " "parameters are allowed or required here." ), )), ("disabled", Checkbox( title=_("Disabled"), label=_( "Currently disable this notification" ), default_value=False, )), ("timeperiod", cmk.gui.watolib.timeperiods. TimeperiodSelection( title=_("Timeperiod"), help= _("Do only notifiy alerts within this time period" ), )), ( "escalation", Tuple( title= _("Restrict to n<sup>th</sup> to m<sup>th</sup> notification (escalation)" ), orientation="float", elements=[ Integer( label=_("from"), help= _("Let through notifications counting from this number" ), default_value=1, minvalue=1, maxvalue=999999, ), Integer( label=_("to"), help= _("Let through notifications counting upto this number" ), default_value=999999, minvalue=1, maxvalue=999999, ), ], ), ), ( "match_sl", Tuple( title=_("Match service level"), help= _("Host or Service must be in the following service level to get notification" ), orientation="horizontal", show_titles=False, elements=[ DropdownChoice( label=_("from:"), choices=cmk.gui.mkeventd. service_levels, prefix_values=True), DropdownChoice( label=_(" to:"), choices=cmk.gui.mkeventd. service_levels, prefix_values=True), ], ), ), ("host_events", ListChoice( title=_("Host Events"), choices=[ ('d', _("Host goes down")), ('u', _("Host gets unreachble")), ('r', _("Host goes up again")), ('f', _("Start or end of flapping state")), ('s', _("Start or end of a scheduled downtime " )), ('x', _("Acknowledgement of host problem") ), ], default_value=[ 'd', 'u', 'r', 'f', 's', 'x' ], )), ("service_events", ListChoice( title=_("Service Events"), choices=[ ('w', _("Service goes into warning state") ), ('u', _("Service goes into unknown state") ), ('c', _("Service goes into critical state") ), ('r', _("Service recovers to OK")), ('f', _("Start or end of flapping state")), ('s', _("Start or end of a scheduled downtime" )), ('x', _("Acknowledgement of service problem" )), ], default_value=[ 'w', 'c', 'u', 'r', 'f', 's', 'x' ], )), ( "only_hosts", ListOfStrings( title=_( "Limit to the following hosts"), help= _("Configure the hosts for this notification. Without prefix, only exact, case sensitive matches, " "<tt>!</tt> for negation and <tt>~</tt> for regex matches." ), orientation="horizontal", # TODO: Clean this up to use an alternative between TextAscii() and RegExp(). Also handle the negation in a different way valuespec=TextAscii(size=20, ), ), ), ( "only_services", ListOfStrings( title=_( "Limit to the following services"), help= _("Configure regular expressions that match the beginning of the service names here. Prefix an " "entry with <tt>!</tt> in order to <i>exclude</i> that service." ), orientation="horizontal", # TODO: Clean this up to use an alternative between TextAscii() and RegExp(). Also handle the negation in a different way valuespec=TextAscii(size=20, ), validate=validate_only_services, ), ), ( "service_blacklist", ListOfStrings( title=_( "Blacklist the following services" ), help= _("Configure regular expressions that match the beginning of the service names here." ), orientation="horizontal", valuespec=RegExp( size=20, mode=RegExp.prefix, ), validate=validate_only_services, ), ), ]), title_function=lambda v: _("Notify by: ") + notification_script_title(v["plugin"]), ), title=_("Flexible Custom Notifications"), add_label=_("Add notification"), ), ), ])