From 523910fc85b40b0f2c718b0700887be3be7d9d14 Mon Sep 17 00:00:00 2001 From: Lars Michelsen Date: Thu, 24 Jan 2019 16:37:00 +0100 Subject: [PATCH] Migrated more register_rule() calls to plugin registry CMK-1572 Change-Id: I16f7811cdcb8ed7130f6b4e14e9c9b54e35b63b6 --- cmk/gui/plugins/views/commands.py | 6 +- cmk/gui/plugins/views/painters.py | 2 +- cmk/gui/plugins/wato/active_checks.py | 4671 +++++++++++---------- cmk/gui/plugins/wato/check_parameters/unsorted.py | 2 +- cmk/gui/plugins/wato/inventory.py | 432 +- cmk/gui/wato/mkeventd.py | 401 +- tests/unit/cmk/gui/watolib/test_rulespecs.py | 2 +- 7 files changed, 2970 insertions(+), 2546 deletions(-) rewrite cmk/gui/plugins/wato/active_checks.py (87%) rewrite cmk/gui/plugins/wato/inventory.py (72%) diff --git a/cmk/gui/plugins/views/commands.py b/cmk/gui/plugins/views/commands.py index 9e3d08b706..4a1d2236f4 100644 --- a/cmk/gui/plugins/views/commands.py +++ b/cmk/gui/plugins/views/commands.py @@ -999,7 +999,7 @@ class CommandScheduleDowntimes(Command): from cmk.gui.cee.plugins.wato.cmc import recurring_downtimes_types recurring_selections = [ - (str(k), v) for (k, v) in sorted(recurring_downtimes_types.items()) + (str(k), v) for (k, v) in sorted(recurring_downtimes_types().items()) ] html.dropdown("_down_recurring", recurring_selections, deflt="3") html.write_text(_("(This only works when using CMC)")) @@ -1012,8 +1012,8 @@ class CommandScheduleDowntimes(Command): if self._has_recurring_downtimes() and html.get_checkbox("_down_do_recur"): from cmk.gui.cee.plugins.wato.cmc import recurring_downtimes_types recurring_type = int(html.request.var("_down_recurring")) - title_start = _( - "schedule a periodic downtime every %s") % recurring_downtimes_types[recurring_type] + title_start = _("schedule a periodic downtime every %s") % recurring_downtimes_types( + )[recurring_type] else: title_start = _("schedule an immediate downtime") diff --git a/cmk/gui/plugins/views/painters.py b/cmk/gui/plugins/views/painters.py index 78c95b2f24..57f2b5acd5 100644 --- a/cmk/gui/plugins/views/painters.py +++ b/cmk/gui/plugins/views/painters.py @@ -4214,7 +4214,7 @@ class PainterDowntimeRecurring(Painter): r = row["downtime_recurring"] if not r: return "", _("no") - return "", recurring_downtimes_types.get(r, _("(unknown: %d)") % r) + return "", recurring_downtimes_types().get(r, _("(unknown: %d)") % r) @painter_registry.register diff --git a/cmk/gui/plugins/wato/active_checks.py b/cmk/gui/plugins/wato/active_checks.py dissimilarity index 87% index f131b002bf..a962654d82 100644 --- a/cmk/gui/plugins/wato/active_checks.py +++ b/cmk/gui/plugins/wato/active_checks.py @@ -1,2169 +1,2502 @@ -#!/usr/bin/python -# -*- encoding: utf-8; py-indent-offset: 4 -*- -# +------------------------------------------------------------------+ -# | ____ _ _ __ __ _ __ | -# | / ___| |__ ___ ___| | __ | \/ | |/ / | -# | | | | '_ \ / _ \/ __| |/ / | |\/| | ' / | -# | | |___| | | | __/ (__| < | | | | . \ | -# | \____|_| |_|\___|\___|_|\_\___|_| |_|_|\_\ | -# | | -# | Copyright Mathias Kettner 2014 mk@mathias-kettner.de | -# +------------------------------------------------------------------+ -# -# This file is part of Check_MK. -# The official homepage is at http://mathias-kettner.de/check_mk. -# -# check_mk is free software; you can redistribute it and/or modify it -# under the terms of the GNU General Public License as published by -# the Free Software Foundation in version 2. check_mk is distributed -# in the hope that it will be useful, but WITHOUT ANY WARRANTY; with- -# out even the implied warranty of MERCHANTABILITY or FITNESS FOR A -# PARTICULAR PURPOSE. See the GNU General Public License for more de- -# tails. You should have received a copy of the GNU General Public -# License along with GNU Make; see the file COPYING. If not, write -# to the Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, -# Boston, MA 02110-1301 USA. - -import six - -import cmk.gui.mkeventd as mkeventd -from cmk.gui.i18n import _ -from cmk.gui.valuespec import ( - Dictionary, - Tuple, - Integer, - Float, - TextAscii, - FixedValue, - Alternative, - ListOfStrings, - Age, - TextUnicode, - DropdownChoice, - RegExp, - RegExpUnicode, - Transform, - EmailAddress, - ListOf, - Checkbox, - RadioChoice, - Password, - Percentage, - CascadingDropdown, - UploadOrPasteTextFile, - Hostname, - Optional, -) - -from cmk.gui.plugins.wato import ( - rulespec_group_registry, - RulespecGroup, - register_rule, - PluginCommandLine, - IndividualOrStoredPassword, -) - - -@rulespec_group_registry.register -class RulespecGroupActiveChecks(RulespecGroup): - @property - def name(self): - return "activechecks" - - @property - def title(self): - return _("Active checks (HTTP, TCP, etc.)") - - @property - def help(self): - return _("Configure active networking checks like HTTP and TCP") - - -# These elements are also used in check_parameters.py -check_icmp_params = [ - ("rta", - Tuple( - title=_("Round trip average"), - elements=[ - Float(title=_("Warning if above"), unit="ms", default_value=200.0), - Float(title=_("Critical if above"), unit="ms", default_value=500.0), - ])), - ("loss", - Tuple( - title=_("Packet loss"), - help=_("When the percentage of lost packets is equal or greater then " - "this level, then the according state is triggered. The default for critical " - "is 100%. That means that the check is only critical if all packets " - "are lost."), - elements=[ - Percentage(title=_("Warning at"), default_value=80.0), - Percentage(title=_("Critical at"), default_value=100.0), - ])), - ("packets", - Integer( - title=_("Number of packets"), - help=_("Number ICMP echo request packets to send to the target host on each " - "check execution. All packets are sent directly on check execution. Afterwards " - "the check waits for the incoming packets."), - minvalue=1, - maxvalue=20, - default_value=5, - )), - ("timeout", - Integer( - title=_("Total timeout of check"), - help=_("After this time (in seconds) the check is aborted, regardless " - "of how many packets have been received yet."), - minvalue=1, - )), -] - -imap_parameters = Dictionary( - title="IMAP", - optional_keys=[], - elements=[ - ('server', - TextAscii( - title=_('IMAP Server'), - allow_empty=False, - help=_('You can specify a hostname or IP address different from the IP address ' - 'of the host this check will be assigned to.'))), - ('ssl', - CascadingDropdown( - title=_('SSL Encryption'), - default_value=(False, 143), - choices=[ - (False, _('Use no encryption'), - Optional( - Integer( - allow_empty=False, - default_value=143, - ), - title=_('TCP Port'), - help=_('By default the standard IMAP Port 143 is used.'), - )), - (True, _('Encrypt IMAP communication using SSL'), - Optional( - Integer( - allow_empty=False, - default_value=993, - ), - title=_('TCP Port'), - help=_('By default the standard IMAP/SSL Port 993 is used.'), - )), - ], - )), - ('auth', - Tuple( - title=_('Authentication'), - elements=[ - TextAscii(title=_('Username'), allow_empty=False, size=24), - IndividualOrStoredPassword(title=_('Password'), allow_empty=False, size=12), - ], - )), - ], -) - -pop3_parameters = Dictionary( - optional_keys=['server'], - elements=[ - ('server', - TextAscii( - title=_('POP3 Server'), - allow_empty=False, - help=_('You can specify a hostname or IP address different from the IP address ' - 'of the host this check will be assigned to.'))), - ('ssl', - CascadingDropdown( - title=_('SSL Encryption'), - default_value=(False, 110), - choices=[ - (False, _('Use no encryption'), - Optional( - Integer( - allow_empty=False, - default_value=110, - ), - title=_('TCP Port'), - help=_('By default the standard POP3 Port 110 is used.'), - )), - (True, _('Encrypt POP3 communication using SSL'), - Optional( - Integer( - allow_empty=False, - default_value=995, - ), - title=_('TCP Port'), - help=_('By default the standard POP3/SSL Port 995 is used.'), - )), - ], - )), - ('auth', - Tuple( - title=_('Authentication'), - elements=[ - TextAscii(title=_('Username'), allow_empty=False, size=24), - IndividualOrStoredPassword(title=_('Password'), allow_empty=False, size=12), - ], - )), - ], -) - -mail_receiving_params = [('fetch', - CascadingDropdown( - title=_('Mail Receiving'), - choices=[ - ('IMAP', _('IMAP'), imap_parameters), - ('POP3', _('POP3'), pop3_parameters), - ]))] - -register_rule( - RulespecGroupActiveChecks, - "active_checks:ssh", - Dictionary( - title=_("Check SSH service"), - help=_("This rulset allow you to configure a SSH check for a host"), - elements=[ - ("description", TextUnicode(title=_("Service Description"),)), - ( - "port", - Integer(title=_("TCP port number"), default_value=22), - ), - ( - "timeout", - Integer( - title=_("Connect Timeout"), - help=_("Seconds before connection times out"), - default_value=10), - ), - ("remote_version", - TextAscii( - title=_("Version of Server"), - help=_("Warn if string doesn't match expected server version (ex: OpenSSH_3.9p1)"), - )), - ("remote_protocol", - TextAscii( - title=_("Protocol of Server"), - help=_("Warn if protocol doesn't match expected protocol version (ex: 2.0)"), - )), - ]), - match="all") - -register_rule( - RulespecGroupActiveChecks, - "active_checks:icmp", - Dictionary( - title=_("Check hosts with PING (ICMP Echo Request)"), - help=_("This ruleset allows you to configure explicit PING monitoring of hosts. " - "Usually a PING is being used as a host check, so this is not neccessary. " - "There are some situations, however, where this can be useful. One of them " - "is when using the Check_MK Micro Core with SMART Ping and you want to " - "track performance data of the PING to some hosts, nevertheless."), - elements=[ - ("description", - TextUnicode( - title=_("Service Description"), - allow_empty=False, - default_value="PING", - )), - ("address", - CascadingDropdown( - title=_("Alternative address to ping"), - help=_("If you omit this setting then the configured IP address of that host " - "will be pinged. You can set an alternative address here (e.g. when " - "you want to check a secondary IP address of the host in question)."), - orientation="horizontal", - choices=[ - ("address", _("Ping the normal IP address")), - ("alias", _("Use the alias as DNS name / IP address")), - ("explicit", _("Ping the following explicit address / DNS name"), Hostname()), - ("all_ipv4addresses", _("Ping all IPv4 addresses")), - ("all_ipv6addresses", _("Ping all IPv6 addresses")), - ("additional_ipv4addresses", _("Ping additional IPv4 addresses")), - ("additional_ipv6addresses", _("Ping additional IPv6 addresses")), - ("indexed_ipv4address", _("Ping IPv4 address identified by its index"), - Integer(default_value=1)), - ("indexed_ipv6address", _("Ping IPv6 address identified by its index"), - Integer(default_value=1)), - ])), - ] + check_icmp_params, - ), - match="all") - - -# Several active checks just had crit levels as one integer -def transform_cert_days(cert_days): - if not isinstance(cert_days, tuple): - return (cert_days, 0) - return cert_days - - -register_rule( - RulespecGroupActiveChecks, - "active_checks:ftp", - Transform( - Dictionary(elements=[ - ("port", Integer( - title=_("Portnumber"), - default_value=21, - )), - ("response_time", - Tuple( - title=_("Expected response time"), - elements=[ - Float(title=_("Warning if above"), unit="ms", default_value=100.0), - Float(title=_("Critical if above"), unit="ms", default_value=200.0), - ])), - ("timeout", - Integer( - title=_("Seconds before connection times out"), - unit=_("sec"), - default_value=10, - )), - ("refuse_state", - DropdownChoice( - title=_("State for connection refusal"), - choices=[ - ('crit', _("CRITICAL")), - ('warn', _("WARNING")), - ('ok', _("OK")), - ])), - ("send_string", TextAscii(title=_("String to send"), size=30)), - ("expect", - ListOfStrings( - title=_("Strings to expect in response"), - orientation="horizontal", - valuespec=TextAscii(size=30), - )), - ("ssl", - FixedValue(value=True, totext=_("use SSL"), title=_("Use SSL for the connection."))), - ( - "cert_days", - Transform( - Tuple( - title=_("SSL certificate validation"), - help=_("Minimum number of days a certificate has to be valid"), - elements=[ - Integer(title=_("Warning at or below"), minvalue=0, unit=_("days")), - Integer(title=_("Critical at or below"), minvalue=0, unit=_("days")), - ], - ), - forth=transform_cert_days, - ), - ), - ]), - forth=lambda x: isinstance(x, tuple) and x[1] or x, - title=_("Check FTP Service"), - ), - match="all") - -register_rule( - RulespecGroupActiveChecks, - "active_checks:sftp", - Tuple( - title=_("Check SFTP Service"), - help= - _("Check functionality of a SFTP server. You can use the default values for putting or getting " - "a file. This file will then be created for the test and deleted afterwards. It will of course not " - "deleted if it was not created by this active check."), - elements=[ - TextAscii(title=_("Hostname"), allow_empty=False), - TextAscii(title=_("Username"), allow_empty=False), - IndividualOrStoredPassword(title=_("Password"), allow_empty=False), - Dictionary(elements=[ - ("description", - TextAscii(title=_("Service Description"), default_value="SFTP", size=30)), - ("port", Integer(title=_("Port"), default_value=22)), - ("timeout", Integer(title=_("Timeout"), default_value=10)), - ( - "timestamp", - TextAscii( - title=_("Timestamp of a remote file"), - size=30, - help=_( - "Show timestamp of a given file. You only need to specify the " - "relative path of the remote file. Examples: \'myDirectory/testfile\' " - " or 'testfile'")), - ), - ("put", - Tuple( - title=_("Put file to SFTP server"), - elements=[ - TextAscii( - title=_("Local file"), - size=30, - default_value="tmp/check_mk_testfile", - help= - _("Local path including filename. Base directory for this relative path " - "will be the home directory of your site. The testfile will be created " - "if it does not exist. Examples: \'tmp/testfile\' (file will be located in " - "$OMD_ROOT/tmp/testfile )")), - TextAscii( - title=_("Remote destination"), - size=30, - default_value="", - help= - _("Remote path where to put the file. If you leave this empty, the file will be placed " - "in the home directory of the user. Example: \'myDirectory\' ")), - ])), - ("get", - Tuple( - title=_("Get file from SFTP server"), - elements=[ - TextAscii( - title=_("Remote file"), - size=30, - default_value="check_mk_testfile", - help= - _("Remote path including filename " - "(e.g. \'testfile\'). If you also enabled " - "'Put file to SFTP server', you can use the same file for both tests." - )), - TextAscii( - title=_("Local destination"), - size=30, - default_value="tmp", - help=_("Local path where to put the downloaded file " - "(e.g. \'tmp\' ).")), - ])), - ]) - ]), - match="all") - -register_rule( - RulespecGroupActiveChecks, - "active_checks:dns", - Tuple( - title=_("Check DNS service"), - help=_("Check the resolution of a hostname into an IP address by a DNS server. " - "This check uses check_dns from the standard Nagios plugins."), - elements=[ - TextAscii( - title=_("Queried Hostname or IP address"), - allow_empty=False, - help=_('The name or IPv4 address you want to query')), - Dictionary( - title=_("Optional parameters"), - elements=[ - ("name", - TextUnicode( - title=_("Alternative Service description"), - help= - _("The service description will be this name instead DNS Servername" - ), - )), - ("server", - Alternative( - title=_("DNS Server"), - elements=[ - FixedValue( - value=None, - totext=_("this host"), - title=_("Use this host as a DNS server for the lookup")), - TextAscii( - title=_("Specify DNS Server"), - allow_empty=False, - help=_("Optional DNS server you want to use for the lookup")), - ])), - ( - "expected_address", - Transform( - ListOfStrings( - title=_("Expected answer (IP address or hostname)"), - help=_("List all allowed expected answers here. If query for an " - "IP address then the answer will be host names, that end " - "with a dot."), - ), - forth=lambda old: isinstance(old, six.string_types) and [old] or old, - ), - ), - ("expected_authority", - FixedValue( - value=True, - title=_("Expect Authoritative DNS Server"), - totext=_("Expect Authoritative"), - )), - ("response_time", - Tuple( - title=_("Expected response time"), - elements=[ - Float(title=_("Warning if above"), unit=_("sec"), default_value=1), - Float(title=_("Critical if above"), unit=_("sec"), default_value=2), - ])), - ("timeout", - Integer( - title=_("Seconds before connection times out"), - unit=_("sec"), - default_value=10, - )), - ]), - ]), - match='all') - -register_rule( - RulespecGroupActiveChecks, - "active_checks:sql", - Dictionary( - title=_("Check SQL Database"), - help=_("This check connects to the specified database, sends a custom SQL-statement " - "or starts a procedure, and checks that the result has a defined format " - "containing three columns, a number, a text, and performance data. Upper or " - "lower levels may be defined here. If they are not defined the number is taken " - "as the state of the check. If a procedure is used, input parameters of the " - "procedures may by given as comma separated list. " - "This check uses the active check check_sql."), - optional_keys=["levels", "levels_low", "perfdata", "port", "procedure", "host"], - elements=[ - ("description", - TextUnicode( - title=_("Service Description"), - help=_("The name of this active service to be displayed."), - allow_empty=False, - )), - ( - "dbms", - DropdownChoice( - title=_("Type of Database"), - choices=[ - ("mysql", _("MySQL")), - ("postgres", _("PostgreSQL")), - ("mssql", _("MSSQL")), - ("oracle", _("Oracle")), - ("db2", _("DB2")), - ], - default_value="postgres", - ), - ), - ("port", - Integer( - title=_("Database Port"), - help=_('The port the DBMS listens to'), - allow_empty=True, - )), - ("name", - TextAscii( - title=_("Database Name"), - help=_('The name of the database on the DBMS'), - allow_empty=False, - )), - ("user", - TextAscii( - title=_("Database User"), - help=_('The username used to connect to the database'), - allow_empty=False, - )), - ("password", - IndividualOrStoredPassword( - title=_("Database Password"), - help=_('The password used to connect to the database'), - allow_empty=False, - )), - ("sql", - Alternative( - title=_("Query or SQL statement"), - elements=[ - TextAscii( - title=_("SQL statement or procedure name"), - help= - _('The SQL-statement or procedure name which is executed on the DBMS. It must return ' - 'a result table with one row and at least two columns. The first column must be ' - 'an integer and is interpreted as the state (0 is OK, 1 is WARN, 2 is CRIT). ' - 'Alternatively the first column can be interpreted as number value and you can ' - 'define levels for this number. The ' - 'second column is used as check output. The third column is optional and can ' - 'contain performance data.')), - UploadOrPasteTextFile( - title=_("Import Query"), - file_title=_("File including Query"), - default_mode="upload", - ), - ], - allow_empty=False, - )), - ( - "procedure", - Dictionary( - optional_keys=["input"], - title=_("Use procedure call instead of SQL statement"), - help=_("If you activate this option, a name of a stored " - "procedure is used instead of an SQL statement. " - "The procedure should return one output variable, " - "which is evaluated in the check. If input parameters " - "are required, they may be specified below."), - elements=[ - ("useprocs", FixedValue( - value=True, - totext=_("procedure call is used"), - )), - ("input", - TextAscii( - title=_("Input Parameters"), - allow_empty=True, - help=_( - "Input parameters, if required by the database procedure. " - "If several parameters are required, use commas to separate them." - ), - )), - ]), - ), - ("levels", - Tuple( - title=_("Upper levels for first output item"), - elements=[Float(title=_("Warning if above")), - Float(title=_("Critical if above"))])), - ("levels_low", - Tuple( - title=_("Lower levels for first output item"), - elements=[Float(title=_("Warning if below")), - Float(title=_("Critical if below"))])), - ("perfdata", - FixedValue( - title=_("Performance Data"), - totext=_("Store output value into RRD database"), - value=True, - )), - ("host", - TextAscii( - title=_("DNS hostname or IP address"), - help=_("This defaults to the host for which the active check is configured."), - )), - ]), - match='all') - -register_rule( - RulespecGroupActiveChecks, - "active_checks:tcp", - Tuple( - title=_("Check connecting to a TCP port"), - help=_("This check tests the connection to a TCP port. It uses " - "check_tcp from the standard Nagios plugins."), - elements=[ - Integer(title=_("TCP Port"), minvalue=1, maxvalue=65535), - Dictionary( - title=_("Optional parameters"), - elements=[ - ("svc_description", - TextUnicode( - title=_("Service description"), - allow_empty=False, - help=_( - "Here you can specify a service description. " - "If this parameter is not set, the service is named TCP Port [PORT NUMBER]" - ))), - ("hostname", - TextAscii( - title=_("DNS Hostname"), - allow_empty=False, - help=_("If you specify a hostname here, then a dynamic DNS lookup " - "will be done instead of using the IP address of the host " - "as configured in your host properties."))), - ("response_time", - Tuple( - title=_("Expected response time"), - elements=[ - Float(title=_("Warning if above"), unit="ms", default_value=100.0), - Float(title=_("Critical if above"), unit="ms", default_value=200.0), - ])), - ("timeout", - Integer( - title=_("Seconds before connection times out"), - unit=_("sec"), - default_value=10, - )), - ("refuse_state", - DropdownChoice( - title=_("State for connection refusal"), - choices=[ - ('crit', _("CRITICAL")), - ('warn', _("WARNING")), - ('ok', _("OK")), - ])), - ("send_string", TextAscii(title=_("String to send"), size=30)), - ("escape_send_string", - FixedValue( - value=True, - title=_( - "Expand \\n, \\r and \\t in the sent string" - ), - totext=_("expand escapes"))), - ("expect", - ListOfStrings( - title=_("Strings to expect in response"), - orientation="horizontal", - valuespec=TextAscii(size=30), - )), - ("expect_all", - FixedValue( - value=True, - totext=_("expect all"), - title=_("Expect all of those strings in the response"))), - ("jail", - FixedValue( - value=True, - title=_("Hide response from socket"), - help=_("As soon as you configure expected strings in " - "the response the check will output the response - " - "as long as you do not hide it with this option"), - totext=_("hide response"))), - ("mismatch_state", - DropdownChoice( - title=_("State for expected string mismatch"), - choices=[ - ('crit', _("CRITICAL")), - ('warn', _("WARNING")), - ('ok', _("OK")), - ])), - ("delay", - Integer( - title=_("Seconds to wait before polling"), - help=_("Seconds to wait between sending string and polling for response"), - unit=_("sec"), - default_value=0, - )), - ( - "maxbytes", - Integer( - title=_("Maximum number of bytes to receive"), - help=_("Close connection once more than this number of " - "bytes are received. Per default the number of " - "read bytes is not limited. This setting is only " - "used if you expect strings in the response."), - default_value=1024, - ), - ), - ("ssl", - FixedValue( - value=True, totext=_("use SSL"), title=_("Use SSL for the connection."))), - ( - "cert_days", - Transform( - Tuple( - title=_("SSL certificate validation"), - help=_("Minimum number of days a certificate has to be valid"), - elements=[ - Integer( - title=_("Warning at or below"), minvalue=0, unit=_("days")), - Integer( - title=_("Critical at or below"), minvalue=0, - unit=_("days")), - ], - ), - forth=transform_cert_days, - ), - ), - ("quit_string", - TextAscii( - title=_("Final string to send"), - help=_("String to send server to initiate a clean close of " - "the connection"), - size=30)), - ]), - ]), - match='all') - -register_rule( - RulespecGroupActiveChecks, "active_checks:uniserv", - Dictionary( - title=_("Check uniserv service"), - optional_keys=False, - elements=[ - ("port", Integer(title=_("Port"))), - ("service", - TextAscii( - title=_("Service Name"), - help= - _("Enter the uniserve service name here (has nothing to do with service description)." - ))), - ("job", - CascadingDropdown( - title=_("Mode of the Check"), - help=_("Choose, whether you just want to query the version number," - " or if you want to check the response to an address query."), - choices=[ - ("version", _("Check for Version")), - ("address", _("Check for an Address"), - Dictionary( - title=_("Address Check mode"), - optional_keys=False, - elements=[ - ("street", TextAscii(title=_("Street name"))), - ("street_no", Integer(title=_("Street number"))), - ("city", TextAscii(title=_("City name"))), - ("search_regex", - TextAscii( - title=_("Check City against Regex"), - help=_("The city name from the response will be checked against " - "the regular expression specified here"), - )), - ])), - ])), - ])) - -ip_address_family_element = ( - "address_family", - DropdownChoice( - title=_("IP Address Family"), - choices=[ - (None, _("Primary Address Family")), - ('ipv4', _("Enforce IPv4")), - ('ipv6', _("Enforce IPv6")), - ], - default_value=None), -) - -register_rule( - RulespecGroupActiveChecks, - "active_checks:http", - Tuple( - title=_("Check HTTP service"), - help=_("Check HTTP/HTTPS service using the plugin check_http " - "from the standard Monitoring Plugins. " - "This plugin tests the HTTP service on the specified host. " - "It can test normal (HTTP) and secure (HTTPS) servers, follow " - "redirects, search for strings and regular expressions, check " - "connection times, and report on certificate expiration times."), - elements=[ - TextUnicode( - title=_("Name"), - help=_( - "Will be used in the service description. If the name starts with " - "a caret (^), the service description will not be prefixed with either " - "HTTP or HTTPS."), - allow_empty=False), - Alternative( - title=_("Mode of the Check"), - help=_("Perform a check of the URL or the certificate expiration."), - elements=[ - Dictionary( - title=_("Check the URL"), - elements=[ - ("virthost", - Tuple( - title=_("Virtual host"), - elements=[ - TextAscii( - title=_("Name of the virtual host"), - help=_( - "Set this in order to specify the name of the " - "virtual host for the query (using HTTP/1.1). If you " - "leave this empty, then the IP address of the host " - "will be used instead."), - allow_empty=False), - Checkbox( - label=_("Omit specifying an IP address"), - help=_( - "Usually Check_MK will nail this check to the " - "IP address of the host it is attached to. With this " - "option you can have the check use the name of the " - "virtual host instead and do a dynamic DNS lookup."), - true_label=_("omit IP address"), - false_label=_("specify IP address"), - ), - ])), - ("uri", - TextAscii( - title=_("URI to fetch (default is /)"), - allow_empty=False, - default_value="/")), - ("port", - Integer( - title=_("TCP Port"), minvalue=1, maxvalue=65535, - default_value=80)), - ip_address_family_element, - ("ssl", - Transform( - DropdownChoice( - title=_("Use SSL/HTTPS for the connection"), - choices=[ - ("auto", _("Use SSL with auto negotiation")), - ("1.2", _("Use SSL, enforce TLSv1.2")), - ("1.1", _("Use SSL, enforce TLSv1.1")), - ("1", _("Use SSL, enforce TLSv1")), - ("2", _("Use SSL, enforce SSLv2")), - ("3", _("Use SSL, enforce SSLv3")), - ], - default_value="auto", - ), - forth=lambda x: x is True and "auto" or x, - )), - ("sni", - FixedValue( - value=True, - totext=_("enable SNI"), - title=_("Enable SSL/TLS hostname extension support (SNI)"), - )), - ("response_time", - Tuple( - title=_("Expected response time"), - elements=[ - Float( - title=_("Warning if above"), - unit="ms", - default_value=100.0), - Float( - title=_("Critical if above"), - unit="ms", - default_value=200.0), - ])), - ("timeout", - Integer( - title=_("Seconds before connection times out"), - unit=_("sec"), - default_value=10, - )), - ( - "user_agent", - TextAscii( - title=_("User Agent"), - help=_("String to be sent in http header as \"User Agent\""), - allow_empty=False, - ), - ), - ( - "add_headers", - ListOfStrings( - title=_("Additional header lines"), - orientation="vertical", - valuespec=TextAscii(size=40), - ), - ), - ("auth", - Tuple( - title=_("Authorization"), - help=_("Credentials for HTTP Basic Authentication"), - elements=[ - TextAscii(title=_("Username"), size=12, allow_empty=False), - IndividualOrStoredPassword(title=_("Password"),) - ])), - ( - "proxy", - TextAscii( - title=_("Proxy host"), - help=_("To use a proxy you have to use the Port of the proxy, " - "specify the virtual host and the URL to fetch, " - "use the HTTP Method CONNECT, and use SSL/HTTPS " - "for the connection")), - ), - ("proxy_auth", - Tuple( - title=_("Proxy-Authorization"), - help=_("Credentials for HTTP Proxy with basic authentication"), - elements=[ - TextAscii(title=_("Username"), size=12, allow_empty=False), - IndividualOrStoredPassword(title=_("Password"),), - ])), - ( - "onredirect", - DropdownChoice( - title=_("How to handle redirect"), - choices=[ - ('ok', _("Make check OK")), - ('warning', _("Make check WARNING")), - ('critical', _("Make check CRITICAL")), - ('follow', _("Follow the redirection")), - ('sticky', _("Follow, but stay to same IP address")), - ('stickyport', - _("Follow, but stay to same IP-address and port")), - ], - default_value='follow'), - ), - ("expect_response_header", - TextAscii(title=_("String to expect in response headers"),)), - ("expect_response", - ListOfStrings( - title=_("Strings to expect in server response"), - help=_("At least one of these strings is expected in " - "the first (status) line of the server response " - "(default: HTTP/1.). If specified skips " - "all other status line logic (ex: 3xx, 4xx, 5xx " - "processing)"), - )), - ("expect_string", - TextUnicode( - title=_("Fixed string to expect in the content"), - allow_empty=False, - )), - ( - "expect_regex", - Transform( - Tuple( - orientation="vertical", - show_titles=False, - elements=[ - RegExp( - label=_("Regular expression: "), - mode=RegExp.infix, - ), - Checkbox(label=_("Case insensitive")), - Checkbox( - label=_("return CRITICAL if found, OK if not")), - Checkbox(label=_("Multiline string matching")), - ]), - forth=lambda x: len(x) == 3 and tuple(list(x) + [False]) or x, - title=_("Regular expression to expect in content"), - ), - ), - ("post_data", - Tuple( - title=_("Send HTTP POST data"), - elements=[ - TextUnicode( - title=_("HTTP POST data"), - help=_("Data to send via HTTP POST method. " - "Please make sure, that the data is URL-encoded."), - size=40, - ), - TextAscii(title=_("Content-Type"), default_value="text/html"), - ])), - ("method", - DropdownChoice( - title=_("HTTP Method"), - default_value="GET", - choices=[ - ("GET", "GET"), - ("POST", "POST"), - ("OPTIONS", "OPTIONS"), - ("TRACE", "TRACE"), - ("PUT", "PUT"), - ("DELETE", "DELETE"), - ("HEAD", "HEAD"), - ("CONNECT", "CONNECT"), - ("PROPFIND", "PROPFIND"), - ])), - ("no_body", - FixedValue( - value=True, - title=_("Don't wait for document body"), - help=_("Note: this still does an HTTP GET or POST, not a HEAD."), - totext=_("don't wait for body"))), - ("page_size", - Tuple( - title=_("Page size to expect"), - elements=[ - Integer(title=_("Minimum"), unit=_("Bytes")), - Integer(title=_("Maximum"), unit=_("Bytes")), - ])), - ("max_age", - Age( - title=_("Maximum age"), - help=_("Warn, if the age of the page is older than this"), - default_value=3600 * 24, - )), - ("urlize", - FixedValue( - value=True, - title=_("Clickable URLs"), - totext=_("Format check output as hyperlink"), - help=_( - "With this option the check produces an output that is a valid hyperlink " - "to the checked URL and this clickable."), - )), - ("extended_perfdata", - FixedValue( - value=True, - totext=_("Extended perfdata"), - title=_("Record additional performance data"), - help= - _("This option makes the HTTP check produce more detailed performance data values " - "like the connect time, header time, time till first byte received and the " - "transfer time."), - )), - ("verbose", - FixedValue( - value=True, - title=_("Verbose output"), - totext=_("Give verbose output"), - )), - ]), - Dictionary( - title=_("Check SSL Certificate Age"), - elements=[ - ( - "cert_days", - Transform( - Tuple( - title=_("Age"), - help=_( - "Minimum number of days a certificate has to be valid. " - "Port defaults to 443. When this option is used the URL " - "is not checked."), - elements=[ - Integer( - title=_("Warning at or below"), - minvalue=0, - unit=_("days")), - Integer( - title=_("Critical at or below"), - minvalue=0, - unit=_("days")), - ], - ), - forth=transform_cert_days, - ), - ), - ( - "cert_host", - TextAscii( - title=_("Check Certificate of different IP / DNS Name"), - help=_( - "For each SSL certificate on a host, a different IP address is needed. " - "Here, you can specify the address if it differs from the " - "address from the host primary address."), - ), - ), - ( - "port", - Integer( - title=_("TCP Port"), - minvalue=1, - maxvalue=65535, - default_value=443, - ), - ), - ip_address_family_element, - ( - "sni", - FixedValue( - value=True, - totext=_("enable SNI"), - title=_("Enable SSL/TLS hostname extension support (SNI)"), - ), - ), - ( - "proxy", - TextAscii( - title=_("Proxy host"), - help=_( - "To use a proxy you have to specify the Port of the proxy. " - )), - ), - ("proxy_auth", - Tuple( - title=_("Proxy-Authorization"), - help=_("Credentials for HTTP Proxy with basic authentication"), - elements=[ - TextAscii(title=_("Username"), size=12, allow_empty=False), - IndividualOrStoredPassword(title=_("Password"),), - ])), - ], - required_keys=["cert_days"], - ), - ]), - ]), - match='all') - -register_rule( - RulespecGroupActiveChecks, - "active_checks:ldap", - Tuple( - title=_("Check access to LDAP service"), - help=_("This check uses check_ldap from the standard " - "Nagios plugins in order to try the response of an LDAP " - "server."), - elements=[ - TextUnicode( - title=_("Name"), - help= - _("The service description will be LDAP plus this name. If the name starts with " - "a caret (^), the service description will not be prefixed with LDAP." - ), - allow_empty=False), - TextAscii( - title=_("Base DN"), - help=_("LDAP base, e.g. ou=Development, o=Mathias Kettner GmbH, c=de"), - allow_empty=False, - size=60), - Dictionary( - title=_("Optional parameters"), - elements=[ - ("attribute", - TextAscii( - title=_("Attribute to search"), - help=_("LDAP attribute to search, " - "The default is (objectclass=*)."), - size=40, - allow_empty=False, - default_value="(objectclass=*)", - )), - ("authentication", - Tuple( - title=_("Authentication"), - elements=[ - TextAscii( - title=_("Bind DN"), - help=_("Distinguished name for binding"), - allow_empty=False, - size=60, - ), - Password( - title=_("Password"), - help= - _("Password for binding, if your server requires an authentication" - ), - allow_empty=False, - size=20, - ) - ])), - ("port", - Integer( - title=_("TCP Port"), - help=_( - "Default is 389 for normal connections and 636 for SSL connections."), - minvalue=1, - maxvalue=65535, - default_value=389)), - ("ssl", - FixedValue( - value=True, - totext=_("Use SSL"), - title=_("Use LDAPS (SSL)"), - help= - _("Use LDAPS (LDAP SSLv2 method). This sets the default port number to 636" - ))), - ("hostname", - TextAscii( - title=_("Alternative Hostname"), - help= - _("Use a alternative field as Hostname in case of SSL Certificate Problems (eg. the Hostalias )" - ), - size=40, - allow_empty=False, - default_value="$HOSTALIAS$", - )), - ("version", - DropdownChoice( - title=_("LDAP Version"), - help=_("The default is to use version 2"), - choices=[ - ("v2", _("Version 2")), - ("v3", _("Version 3")), - ("v3tls", _("Version 3 and TLS")), - ], - default_value="v2", - )), - ("response_time", - Tuple( - title=_("Expected response time"), - elements=[ - Float(title=_("Warning if above"), unit="ms", default_value=1000.0), - Float(title=_("Critical if above"), unit="ms", default_value=2000.0), - ])), - ("timeout", - Integer( - title=_("Seconds before connection times out"), - unit=_("sec"), - default_value=10, - )), - ]) - ]), - match='all') - - -def transform_smtp_address_family(val): - if "ip_version" in val: - val["address_family"] = val.pop("ip_version") - return val - - -register_rule( - RulespecGroupActiveChecks, - "active_checks:smtp", - Tuple( - title=_("Check access to SMTP services"), - help=_("This check uses check_smtp from the standard " - "Nagios plugins in order to try the response of an SMTP " - "server."), - elements=[ - TextUnicode( - title=_("Name"), - help= - _("The service description will be SMTP plus this name. If the name starts with " - "a caret (^), the service description will not be prefixed with SMTP." - ), - allow_empty=False), - Transform( - Dictionary( - title=_("Optional parameters"), - elements=[ - ("hostname", - TextAscii( - title=_("DNS Hostname or IP address"), - allow_empty=False, - help=_( - "You can specify a hostname or IP address different from the IP address " - "of the host as configured in your host properties."))), - ("port", - Transform( - Integer( - title=_("TCP Port to connect to"), - help=_("The TCP Port the SMTP server is listening on. " - "The default is 25."), - size=5, - minvalue=1, - maxvalue=65535, - default_value="25", - ), - forth=int, - )), - ip_address_family_element, - ("expect", - TextAscii( - title=_("Expected String"), - help=_("String to expect in first line of server response. " - "The default is 220."), - size=8, - allow_empty=False, - default_value="220", - )), - ('commands', - ListOfStrings( - title=_("SMTP Commands"), - help=_("SMTP commands to execute."), - )), - ('command_responses', - ListOfStrings( - title=_("SMTP Responses"), - help=_("Expected responses to the given SMTP commands."), - )), - ("from", - TextAscii( - title=_("FROM-Address"), - help=_( - "FROM-address to include in MAIL command, required by Exchange 2000" - ), - size=20, - allow_empty=True, - default_value="", - )), - ("fqdn", - TextAscii( - title=_("FQDN"), - help=_("FQDN used for HELO"), - size=20, - allow_empty=True, - default_value="", - )), - ("cert_days", - Transform( - Tuple( - title=_("Minimum Certificate Age"), - help=_("Minimum number of days a certificate has to be valid"), - elements=[ - Integer( - title=_("Warning at or below"), minvalue=0, - unit=_("days")), - Integer( - title=_("Critical at or below"), - minvalue=0, - unit=_("days")), - ], - ), - forth=transform_cert_days, - )), - ("starttls", - FixedValue( - True, - totext=_("STARTTLS enabled."), - title=_("Use STARTTLS for the connection."))), - ("auth", - Tuple( - title=_("Enable SMTP AUTH (LOGIN)"), - help=_("SMTP AUTH type to check (default none, only LOGIN supported)"), - elements=[ - TextAscii(title=_("Username"), size=12, allow_empty=False), - Password(title=_("Password"), size=12, allow_empty=False), - ])), - ("response_time", - Tuple( - title=_("Expected response time"), - elements=[ - Integer(title=_("Warning if above"), unit=_("sec")), - Integer(title=_("Critical if above"), unit=_("sec")), - ])), - ("timeout", - Integer( - title=_("Seconds before connection times out"), - unit=_("sec"), - default_value=10, - )), - ]), - forth=transform_smtp_address_family, - ) - ]), - match='all') - -register_rule( - RulespecGroupActiveChecks, - "active_checks:disk_smb", - Dictionary( - title=_("Check access to SMB share"), - help=_("This ruleset helps you to configure the classical Nagios " - "plugin check_disk_smb that checks the access to " - "filesystem shares that are exported via SMB/CIFS."), - elements=[ - ("share", - TextUnicode( - title=_("SMB share to check"), - help=_("Enter the plain name of the share only, e. g. iso, not " - "the full UNC like \\\\servername\\iso"), - size=32, - allow_empty=False, - )), - ("workgroup", - TextUnicode( - title=_("Workgroup"), - help=_("Workgroup or domain used (defaults to WORKGROUP)"), - size=32, - allow_empty=False, - )), - ("host", - TextAscii( - title=_("NetBIOS name of the server"), - help=_("If omitted then the IP address is being used."), - size=32, - allow_empty=False, - )), - ("port", - Integer( - title=_("TCP Port"), - help=_("TCP port number to connect to. Usually either 139 or 445."), - default_value=445, - minvalue=1, - maxvalue=65535, - )), - ("levels", - Tuple( - title=_("Levels for used disk space"), - elements=[ - Percentage(title=_("Warning if above"), default_value=85, allow_int=True), - Percentage(title=_("Critical if above"), default_value=95, allow_int=True), - ])), - ("auth", - Tuple( - title=_("Authorization"), - elements=[ - TextAscii(title=_("Username"), allow_empty=False, size=24), - Password(title=_("Password"), allow_empty=False, size=12), - ], - )), - ], - required_keys=["share", "levels"], - ), - match='all') - -register_rule( - RulespecGroupActiveChecks, - "custom_checks", - Dictionary( - title=_("Classical active and passive Monitoring checks"), - help=_("With this ruleset you can configure "classical Monitoring checks" " - "to be executed directly on your monitoring server. These checks " - "will not use Check_MK. It is also possible to configure passive " - "checks that are fed with data from external sources via the " - "command pipe of the monitoring core."), - elements=[ - ("service_description", - TextUnicode( - title=_("Service description"), - help=_("Please make sure that this is unique per host " - "and does not collide with other services."), - allow_empty=False, - default_value=_("Customcheck"))), - ( - "command_line", - PluginCommandLine(), - ), - ("command_name", - TextAscii( - title=_("Internal command name"), - help=_("If you want, you can specify a name that will be used " - "in the define command section for these checks. This " - "allows you to a assign a custom PNP template for the performance " - "data of the checks. If you omit this, then check-mk-custom " - "will be used."), - size=32)), - ("has_perfdata", - FixedValue( - title=_("Performance data"), - value=True, - totext=_("process performance data"), - )), - ("freshness", - Dictionary( - title=_("Check freshness"), - help= - _("Freshness checking is only useful for passive checks when the staleness feature " - "is not enough for you. It changes the state of a check to a configurable other state " - "when the check results are not arriving in time. Staleness will still grey out the " - "test after the corrsponding interval. If you don't want that, you might want to adjust " - "the staleness interval as well. The staleness interval is calculated from the normal " - "check interval multiplied by the staleness value in the Global Settings. " - "The normal check interval can be configured in a separate rule for your check." - ), - optional_keys=False, - elements=[ - ("interval", - Integer( - title=_("Expected update interval"), - label=_("Updates are expected at least every"), - unit=_("minutes"), - minvalue=1, - default_value=10, - )), - ("state", - DropdownChoice( - title=_("State in case of absent updates"), - choices=[ - (1, _("WARN")), - (2, _("CRIT")), - (3, _("UNKNOWN")), - ], - default_value=3, - )), - ("output", - TextUnicode( - title=_("Plugin output in case of absent updates"), - size=40, - allow_empty=False, - default_value=_("Check result did not arrive in time"))), - ], - )), - ], - required_keys=["service_description"], - ), - match='all') - -register_rule( - RulespecGroupActiveChecks, - "active_checks:bi_aggr", - Tuple( - title=_("Check State of BI Aggregation"), - help=_( - "Connect to the local or a remote monitoring host, which uses Check_MK BI to aggregate " - "several states to a single BI aggregation, which you want to show up as a single " - "service."), - elements=[ - TextAscii( - title=_("Base URL (OMD Site)"), - help= - _("The base URL to the monitoring instance. For example http://mycheckmk01/mysite. " - "You can use macros like $HOSTADDRESS$ and $HOSTNAME$ within this URL to " - "make them be replaced by the hosts values."), - size=60, - allow_empty=False), - TextAscii( - title=_("Aggregation Name"), - help= - _("The name of the aggregation to fetch. It will be added to the service description. You can " - "use macros like $HOSTADDRESS$ and $HOSTNAME$ within this parameter to " - "make them be replaced by the hosts values. The aggregation name is the title in the " - "top-level-rule of your BI pack."), - allow_empty=False), - TextAscii( - title=_("Username"), - help= - _("The name of the user account to use for fetching the BI aggregation via HTTP. When " - "using the cookie based authentication mode (default), this must be a user where " - "authentication is set to \"Automation Secret\" based authentication."), - allow_empty=False), - IndividualOrStoredPassword( - title=_("Password / Secret"), - help=_( - "Valid automation secret or password for the user, depending on the chosen " - "authentication mode. Be aware that this mode has to be enabled on the monitoring instance. " - "Otherwise authentication will fail."), - allow_empty=False), - Dictionary( - title=_("Optional parameters"), - elements=[ - ("auth_mode", - DropdownChoice( - title=_('Authentication Mode'), - default_value='cookie', - choices=[ - ('cookie', _('Form (Cookie) based')), - ('basic', _('HTTP Basic')), - ('digest', _('HTTP Digest')), - ('kerberos', _('Kerberos')), - ], - )), - ("timeout", - Integer( - title=_("Seconds before connection times out"), - unit=_("sec"), - default_value=60, - )), - ("in_downtime", - RadioChoice( - title=_("State, if BI aggregate is in scheduled downtime"), - orientation="vertical", - choices=[ - (None, _("Use normal state, ignore downtime")), - ("ok", _("Force to be OK")), - ("warn", _("Force to be WARN, if aggregate is not OK")), - ])), - ("acknowledged", - RadioChoice( - title=_("State, if BI aggregate is acknowledged"), - orientation="vertical", - choices=[ - (None, _("Use normal state, ignore acknowledgement")), - ("ok", _("Force to be OK")), - ("warn", _("Force to be WARN, if aggregate is not OK")), - ])), - ("track_downtimes", - Checkbox( - title=_("Track downtimes"), - label=_("Automatically track downtimes of aggregation"), - help=_("If this is active, the check will automatically go into downtime " - "whenever the aggregation does. This downtime is also cleaned up " - "automatically when the aggregation leaves downtime. " - "Downtimes you set manually for this check are unaffected."), - )), - ]), - ]), - match='all') - -register_rule( - RulespecGroupActiveChecks, - "active_checks:form_submit", - Tuple( - title=_("Check HTML Form Submit"), - help= - _("Check submission of HTML forms via HTTP/HTTPS using the plugin check_form_submit " - "provided with Check_MK. This plugin provides more functionality as check_http, " - "as it automatically follows HTTP redirect, accepts and uses cookies, parses forms " - "from the requested pages, changes vars and submits them to check the response " - "afterwards."), - elements=[ - TextUnicode( - title=_("Name"), - help=_("The name will be used in the service description"), - allow_empty=False), - Dictionary( - title=_("Check the URL"), - elements=[ - ("hosts", - ListOfStrings( - title=_('Check specific host(s)'), - help=_('By default, if you do not specify any host addresses here, ' - 'the host address of the host this service is assigned to will ' - 'be used. But by specifying one or several host addresses here, ' - 'it is possible to let the check monitor one or multiple hosts.'))), - ("virthost", - TextAscii( - title=_("Virtual host"), - help=_("Set this in order to specify the name of the " - "virtual host for the query (using HTTP/1.1). When you " - "leave this empty, then the IP address of the host " - "will be used instead."), - allow_empty=False, - )), - ("uri", - TextAscii( - title=_("URI to fetch (default is /)"), - allow_empty=False, - default_value="/", - regex='^/.*', - )), - ("port", - Integer( - title=_("TCP Port"), - minvalue=1, - maxvalue=65535, - default_value=80, - )), - ("ssl", - FixedValue( - value=True, - totext=_("use SSL/HTTPS"), - title=_("Use SSL/HTTPS for the connection."))), - ("timeout", - Integer( - title=_("Seconds before connection times out"), - unit=_("sec"), - default_value=10, - )), - ("expect_regex", - RegExp( - title=_("Regular expression to expect in content"), - mode=RegExp.infix, - )), - ("form_name", - TextAscii( - title=_("Name of the form to populate and submit"), - help=_("If there is only one form element on the requested page, you " - "do not need to provide the name of that form here. But if you " - "have several forms on that page, you need to provide the name " - "of the form here, to enable the check to identify the correct " - "form element."), - allow_empty=True, - )), - ("query", - TextAscii( - title=_("Send HTTP POST data"), - help=_( - "Data to send via HTTP POST method. Please make sure, that the data " - "is URL-encoded (for example \"key1=val1&key2=val2\")."), - size=40, - )), - ("num_succeeded", - Tuple( - title=_("Multiple Hosts: Number of successful results"), - elements=[ - Integer(title=_("Warning if equal or below")), - Integer(title=_("Critical if equal or below")), - ])), - ]), - ]), - match='all') - -register_rule( - RulespecGroupActiveChecks, - "active_checks:notify_count", - Tuple( - title=_("Check Number of Notifications per Contact"), - help= - _("Check the number of sent notifications per contact using the plugin check_notify_count " - "provided with Check_MK. This plugin counts the total number of notifications sent by the local " - "monitoring core and creates graphs for each individual contact. You can configure thresholds " - "on the number of notifications per contact in a defined time interval. " - "This plugin queries livestatus to extract the notification related log entries from the " - "log file of your monitoring core."), - elements=[ - TextUnicode( - title=_("Service Description"), - help=_("The name that will be used in the service description"), - allow_empty=False), - Integer( - title=_("Interval to monitor"), - label=_("notifications within last"), - unit=_("minutes"), - minvalue=1, - default_value=60, - ), - Dictionary( - title=_("Optional parameters"), - elements=[ - ("num_per_contact", - Tuple( - title=_("Thresholds for Notifications per Contact"), - elements=[ - Integer(title=_("Warning if above"), default_value=20), - Integer(title=_("Critical if above"), default_value=50), - ])), - ]), - ]), - match='all') - -register_rule( - RulespecGroupActiveChecks, - "active_checks:traceroute", - Dictionary( - title=_("Check current routing (uses traceroute)"), - help=_("This active check uses traceroute in order to determine the current " - "routing from the monitoring host to the target host. You can specify any number " - "of missing or expected routes in that way detect e.g. an (unintended) failover " - "to a secondary route."), - elements=[ - ("dns", - Checkbox( - title=_("Name resolution"), - label=_("Use DNS to convert IP addresses into hostnames"), - help=_("If you use this option, then traceroute is not being " - "called with the option -n. That means that all IP addresses " - "are tried to be converted into names. This usually adds additional " - "execution time. Also DNS resolution might fail for some addresses."), - )), - ("routers", - ListOf( - Tuple(elements=[ - TextAscii( - title=_("Router (FQDN, IP-Address)"), - allow_empty=False, - ), - DropdownChoice( - title=_("How"), - choices=[ - ('W', _("WARN - if this router is not being used")), - ('C', _("CRIT - if this router is not being used")), - ('w', _("WARN - if this router is being used")), - ('c', _("CRIT - if this router is being used")), - ]), - ]), - title=_("Router that must or must not be used"), - add_label=_("Add Condition"), - )), - ("method", - DropdownChoice( - title=_("Method of probing"), - choices=[ - (None, _("UDP (default behaviour of tcpdump)")), - ("icmp", _("ICMP Echo Request")), - ("tcp", _("TCP SYN")), - ])), - ], - optional_keys=False, - ), - match='all') - -register_rule( - RulespecGroupActiveChecks, - 'active_checks:mail_loop', - Dictionary( - title=_('Check Email Delivery'), - help=_('This active check sends out special E-Mails to a defined mail address using ' - 'the SMTP protocol and then tries to receive these mails back by querying the ' - 'inbox of a IMAP or POP3 mailbox. With this check you can verify that your whole ' - 'mail delivery progress is working.'), - optional_keys=[ - 'subject', 'smtp_server', 'smtp_tls', 'smtp_port', 'smtp_auth', 'imap_tls', - 'connect_timeout', 'delete_messages', 'duration' - ], - elements=[ - ('item', - TextUnicode( - title=_('Name'), - help=_('The service description will be Mail Loop plus this name'), - allow_empty=False)), - ('subject', - TextAscii( - title=_('Subject'), - allow_empty=False, - help=_('Here you can specify the subject text ' - 'instead of default text \'Check_MK-Mail-Loop\'.'), - )), - ('smtp_server', - TextAscii( - title=_('SMTP Server'), - allow_empty=False, - help=_('You can specify a hostname or IP address different from the IP address ' - 'of the host this check will be assigned to.'))), - ('smtp_tls', - FixedValue( - True, - title=_('Use TLS over SMTP'), - totext=_('Encrypt SMTP communication using TLS'), - )), - ('imap_tls', - FixedValue( - True, - title=_('Use TLS for IMAP authentification'), - totext=_('IMAP authentification uses TLS'), - )), - ('smtp_port', - Integer( - title=_('SMTP TCP Port to connect to'), - help=_('The TCP Port the SMTP server is listening on. Defaulting to 25.'), - allow_empty=False, - default_value=25, - )), - ('smtp_auth', - Tuple( - title=_('SMTP Authentication'), - elements=[ - TextAscii(title=_('Username'), allow_empty=False, size=24), - IndividualOrStoredPassword(title=_('Password'), allow_empty=False, size=12), - ], - )), - ] + mail_receiving_params + [ - ('mail_from', EmailAddress(title=_('From: email address'),)), - ('mail_to', EmailAddress(title=_('Destination email address'),)), - ('connect_timeout', - Integer( - title=_('Connect Timeout'), - minvalue=1, - default_value=10, - unit=_('sec'), - )), - ("duration", - Tuple( - title=_("Loop duration"), - elements=[ - Age(title=_("Warning at")), - Age(title=_("Critical at")), - ])), - ('delete_messages', - FixedValue( - True, - title=_('Delete processed messages'), - totext=_('Delete all processed message belonging to this check'), - help=_('Delete all messages identified as being related to this ' - 'check. This is disabled by default, which will make ' - 'your mailbox grow when you not clean it up on your own.'), - )), - ]), - match='all') - -register_rule( - RulespecGroupActiveChecks, - 'active_checks:mail', - Dictionary( - title=_('Check Email'), - help=_('The basic function of this check is to log in into an IMAP or POP3 mailbox to ' - 'monitor whether or not the login is possible. A extended feature is, that the ' - 'check can fetch all (or just some) from the mailbox and forward them as events ' - 'to the Event Console.'), - required_keys=['service_description', 'fetch'], - elements=[('service_description', - TextUnicode( - title=_('Service description'), - help=_('Please make sure that this is unique per host ' - 'and does not collide with other services.'), - allow_empty=False, - default_value="Email"))] + mail_receiving_params + - [ - ('connect_timeout', - Integer( - title=_('Connect Timeout'), - minvalue=1, - default_value=10, - unit=_('sec'), - )), - ( - 'forward', - Dictionary( - title=_("Forward mails as events to Event Console"), - elements=[ - ( - 'method', - Alternative( - title=_("Forwarding Method"), - elements=[ - Alternative( - title=_("Send events to local event console"), - elements=[ - FixedValue( - "", - totext=_("Directly forward to event console"), - title= - _("Send events to local event console in same OMD site" - ), - ), - TextAscii( - title= - _("Send events to local event console into unix socket" - ), - allow_empty=False, - ), - FixedValue( - "spool:", - totext=_("Spool to event console"), - title= - _("Spooling: Send events to local event console in same OMD site" - ), - ), - Transform( - TextAscii(), - title= - _("Spooling: Send events to local event console into given spool directory" - ), - allow_empty=False, - # remove prefix - forth=lambda x: x[6:], - back=lambda x: "spool:" + x, # add prefix - ), - ], - match= - lambda x: x and (x == 'spool:' and 2 or x.startswith('spool:') and 3 or 1) or 0 - ), - Tuple( - title=_("Send events to remote syslog host"), - elements=[ - DropdownChoice( - choices=[ - ('udp', _('UDP')), - ('tcp', _('TCP')), - ], - title=_("Protocol"), - ), - TextAscii( - title=_("Address"), - allow_empty=False, - ), - Integer( - title=_("Port"), - allow_empty=False, - default_value=514, - minvalue=1, - maxvalue=65535, - size=6, - ), - ]), - ], - )), - ('match_subject', - RegExpUnicode( - title=_('Only process mails with matching subject'), - help=_( - 'Use this option to not process all messages found in the inbox, ' - 'but only the those whose subject matches the given regular expression.' - ), - mode=RegExp.prefix, - )), - ( - 'facility', - DropdownChoice( - title=_("Events: Syslog facility"), - help=_("Use this syslog facility for all created events"), - choices=mkeventd.syslog_facilities, - default_value=2, # mail - )), - ('application', - Alternative( - title=_("Events: Syslog application"), - help=_("Use this syslog application for all created events"), - elements=[ - FixedValue( - None, - title=_("Use the mail subject"), - totext=_("The mail subject is used as syslog appliaction"), - ), - TextUnicode( - title=_("Specify the application"), - help= - _("Use this text as application. You can use macros like \\1, \\2, ... " - "here when you configured subject matching in this rule with a regular expression " - "that declares match groups (using braces)."), - allow_empty=False, - ), - ])), - ('host', - TextAscii( - title=_('Events: Hostname'), - help= - _('Use this hostname for all created events instead of the name of the mailserver' - ), - )), - ('body_limit', - Integer( - title=_('Limit length of mail body'), - help=_( - 'When forwarding mails from the mailbox to the event console, the ' - 'body of the mail is limited to the given number of characters.'), - default_value=1000, - )), - ('cleanup', - Alternative( - title=_("Cleanup messages"), - help= - _("The handled messages (see subject matching) can be cleaned up by either " - "deleting them or moving them to a subfolder. By default nothing is cleaned up." - ), - elements=[ - FixedValue( - True, - title=_('Delete messages'), - totext=_( - 'Delete all processed message belonging to this check'), - ), - TextUnicode( - title=_("Move to subfolder"), - help=_( - "Specify the destination path in the format Path/To/Folder, for example" - "INBOX/Processed_Mails."), - allow_empty=False, - ), - ])), - ])), - ]), - match='all') - -register_rule( - RulespecGroupActiveChecks, - 'active_checks:mailboxes', - Dictionary( - title=_('Check IMAP Mailboxes'), - help=_('This check monitors count and age of mails in mailboxes.'), - elements=[('service_description', - TextUnicode( - title=_('Service description'), - help=_('Please make sure that this is unique per host ' - 'and does not collide with other services.'), - allow_empty=False, - default_value="Mailboxes")), ('imap_parameters', imap_parameters), - ('connect_timeout', - Integer( - title=_('Connect Timeout'), - minvalue=1, - default_value=10, - unit=_('sec'), - )), - ('age', - Tuple( - title=_("Message Age"), - elements=[Age(title=_("Warning at")), - Age(title=_("Critical at"))])), - ('count', - Tuple( - title=_("Message Count"), - elements=[Integer(title=_("Warning at")), - Integer(title=_("Critical at"))])), - ('mailboxes', - ListOfStrings( - title=_('Check only the listed mailboxes'), - help=_('By default, all mailboxes are checked with these parameters. ' - 'If you specify mailboxes here, only those are monitored.')))], - required_keys=['service_description', 'imap_parameters']), - match='all') - -register_rule( - RulespecGroupActiveChecks, - "active_checks:by_ssh", - Tuple( - title=_("Check via SSH service"), - help=_("Checks via SSH. "), - elements=[ - TextAscii( - title=_("Command"), - help=_("Command to execute on remote host."), - allow_empty=False, - ), - Dictionary( - title=_("Optional parameters"), - elements=[ - ("description", - TextAscii( - title=_("Service Description"), - help=_( - "Must be unique for every host. Defaults to command that is executed." - ), - size=30)), - ("hostname", - TextAscii( - title=_("DNS Hostname or IP address"), - default_value="$HOSTADDRESS$", - allow_empty=False, - help=_( - "You can specify a hostname or IP address different from IP address " - "of the host as configured in your host properties."))), - ('port', - Integer( - title=_("SSH Port"), - help=_("Default is 22."), - minvalue=1, - maxvalue=65535, - default_value=22)), - ("ip_version", - Alternative( - title=_("IP-Version"), - elements=[ - FixedValue("ipv4", totext="", title=_("IPv4")), - FixedValue("ipv6", totext="", title=_("IPv6")), - ], - )), - ("timeout", - Integer( - title=_("Seconds before connection times out"), - unit=_("sec"), - default_value=10, - )), - ("logname", - TextAscii( - title=_("Username"), help=_("SSH user name on remote host"), size=30)), - ("identity", - TextAscii( - title=_("Keyfile"), help=_("Identity of an authorized key"), size=30)), - ]) - ]), - match='all') +#!/usr/bin/python +# -*- encoding: utf-8; py-indent-offset: 4 -*- +# +------------------------------------------------------------------+ +# | ____ _ _ __ __ _ __ | +# | / ___| |__ ___ ___| | __ | \/ | |/ / | +# | | | | '_ \ / _ \/ __| |/ / | |\/| | ' / | +# | | |___| | | | __/ (__| < | | | | . \ | +# | \____|_| |_|\___|\___|_|\_\___|_| |_|_|\_\ | +# | | +# | Copyright Mathias Kettner 2014 mk@mathias-kettner.de | +# +------------------------------------------------------------------+ +# +# This file is part of Check_MK. +# The official homepage is at http://mathias-kettner.de/check_mk. +# +# check_mk is free software; you can redistribute it and/or modify it +# under the terms of the GNU General Public License as published by +# the Free Software Foundation in version 2. check_mk is distributed +# in the hope that it will be useful, but WITHOUT ANY WARRANTY; with- +# out even the implied warranty of MERCHANTABILITY or FITNESS FOR A +# PARTICULAR PURPOSE. See the GNU General Public License for more de- +# tails. You should have received a copy of the GNU General Public +# License along with GNU Make; see the file COPYING. If not, write +# to the Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, +# Boston, MA 02110-1301 USA. + +import six + +import cmk.gui.mkeventd as mkeventd +from cmk.gui.i18n import _ +from cmk.gui.valuespec import ( + Dictionary, + Tuple, + Integer, + Float, + TextAscii, + FixedValue, + Alternative, + ListOfStrings, + Age, + TextUnicode, + DropdownChoice, + RegExp, + RegExpUnicode, + Transform, + EmailAddress, + ListOf, + Checkbox, + RadioChoice, + Password, + Percentage, + CascadingDropdown, + UploadOrPasteTextFile, + Hostname, + Optional, +) + +from cmk.gui.plugins.wato import ( + rulespec_group_registry, + RulespecGroup, + rulespec_registry, + HostRulespec, + PluginCommandLine, + IndividualOrStoredPassword, +) + + +@rulespec_group_registry.register +class RulespecGroupActiveChecks(RulespecGroup): + @property + def name(self): + return "activechecks" + + @property + def title(self): + return _("Active checks (HTTP, TCP, etc.)") + + @property + def help(self): + return _("Configure active networking checks like HTTP and TCP") + + +# These elements are also used in check_parameters.py +def check_icmp_params(): + return [ + ("rta", + Tuple( + title=_("Round trip average"), + elements=[ + Float(title=_("Warning if above"), unit="ms", default_value=200.0), + Float(title=_("Critical if above"), unit="ms", default_value=500.0), + ])), + ("loss", + Tuple( + title=_("Packet loss"), + help=_("When the percentage of lost packets is equal or greater then " + "this level, then the according state is triggered. The default for critical " + "is 100%. That means that the check is only critical if all packets " + "are lost."), + elements=[ + Percentage(title=_("Warning at"), default_value=80.0), + Percentage(title=_("Critical at"), default_value=100.0), + ])), + ("packets", + Integer( + title=_("Number of packets"), + help=_("Number ICMP echo request packets to send to the target host on each " + "check execution. All packets are sent directly on check execution. Afterwards " + "the check waits for the incoming packets."), + minvalue=1, + maxvalue=20, + default_value=5, + )), + ("timeout", + Integer( + title=_("Total timeout of check"), + help=_("After this time (in seconds) the check is aborted, regardless " + "of how many packets have been received yet."), + minvalue=1, + )), + ] + + +def _imap_parameters(): + return Dictionary( + title="IMAP", + optional_keys=[], + elements=[ + ('server', + TextAscii( + title=_('IMAP Server'), + allow_empty=False, + help=_('You can specify a hostname or IP address different from the IP address ' + 'of the host this check will be assigned to.'))), + ('ssl', + CascadingDropdown( + title=_('SSL Encryption'), + default_value=(False, 143), + choices=[ + (False, _('Use no encryption'), + Optional( + Integer( + allow_empty=False, + default_value=143, + ), + title=_('TCP Port'), + help=_('By default the standard IMAP Port 143 is used.'), + )), + (True, _('Encrypt IMAP communication using SSL'), + Optional( + Integer( + allow_empty=False, + default_value=993, + ), + title=_('TCP Port'), + help=_('By default the standard IMAP/SSL Port 993 is used.'), + )), + ], + )), + ('auth', + Tuple( + title=_('Authentication'), + elements=[ + TextAscii(title=_('Username'), allow_empty=False, size=24), + IndividualOrStoredPassword(title=_('Password'), allow_empty=False, size=12), + ], + )), + ], + ) + + +def _pop3_parameters(): + return Dictionary( + optional_keys=['server'], + elements=[ + ('server', + TextAscii( + title=_('POP3 Server'), + allow_empty=False, + help=_('You can specify a hostname or IP address different from the IP address ' + 'of the host this check will be assigned to.'))), + ('ssl', + CascadingDropdown( + title=_('SSL Encryption'), + default_value=(False, 110), + choices=[ + (False, _('Use no encryption'), + Optional( + Integer( + allow_empty=False, + default_value=110, + ), + title=_('TCP Port'), + help=_('By default the standard POP3 Port 110 is used.'), + )), + (True, _('Encrypt POP3 communication using SSL'), + Optional( + Integer( + allow_empty=False, + default_value=995, + ), + title=_('TCP Port'), + help=_('By default the standard POP3/SSL Port 995 is used.'), + )), + ], + )), + ('auth', + Tuple( + title=_('Authentication'), + elements=[ + TextAscii(title=_('Username'), allow_empty=False, size=24), + IndividualOrStoredPassword(title=_('Password'), allow_empty=False, size=12), + ], + )), + ], + ) + + +def _mail_receiving_params(): + return [ + ('fetch', + CascadingDropdown( + title=_('Mail Receiving'), + choices=[ + ('IMAP', _('IMAP'), _imap_parameters()), + ('POP3', _('POP3'), _pop3_parameters()), + ])), + ] + + +@rulespec_registry.register +class RulespecActiveChecksSsh(HostRulespec): + @property + def group(self): + return RulespecGroupActiveChecks + + @property + def name(self): + return "active_checks:ssh" + + @property + def match_type(self): + return "all" + + @property + def valuespec(self): + return Dictionary( + title=_("Check SSH service"), + help=_("This rulset allow you to configure a SSH check for a host"), + elements=[ + ("description", TextUnicode(title=_("Service Description"),)), + ( + "port", + Integer( + title=_("TCP port number"), + default_value=22, + ), + ), + ( + "timeout", + Integer( + title=_("Connect Timeout"), + help=_("Seconds before connection times out"), + default_value=10), + ), + ("remote_version", + TextAscii( + title=_("Version of Server"), + help=_( + "Warn if string doesn't match expected server version (ex: OpenSSH_3.9p1)" + ), + )), + ("remote_protocol", + TextAscii( + title=_("Protocol of Server"), + help=_("Warn if protocol doesn't match expected protocol version (ex: 2.0)"), + )), + ], + ) + + +@rulespec_registry.register +class RulespecActiveChecksIcmp(HostRulespec): + @property + def group(self): + return RulespecGroupActiveChecks + + @property + def name(self): + return "active_checks:icmp" + + @property + def match_type(self): + return "all" + + @property + def valuespec(self): + return Dictionary( + title=_("Check hosts with PING (ICMP Echo Request)"), + help=_("This ruleset allows you to configure explicit PING monitoring of hosts. " + "Usually a PING is being used as a host check, so this is not neccessary. " + "There are some situations, however, where this can be useful. One of them " + "is when using the Check_MK Micro Core with SMART Ping and you want to " + "track performance data of the PING to some hosts, nevertheless."), + elements=[ + ("description", + TextUnicode( + title=_("Service Description"), + allow_empty=False, + default_value="PING", + )), + ("address", + CascadingDropdown( + title=_("Alternative address to ping"), + help=_("If you omit this setting then the configured IP address of that host " + "will be pinged. You can set an alternative address here (e.g. when " + "you want to check a secondary IP address of the host in question)."), + orientation="horizontal", + choices=[ + ("address", _("Ping the normal IP address")), + ("alias", _("Use the alias as DNS name / IP address")), + ("explicit", _("Ping the following explicit address / DNS name"), + Hostname()), + ("all_ipv4addresses", _("Ping all IPv4 addresses")), + ("all_ipv6addresses", _("Ping all IPv6 addresses")), + ("additional_ipv4addresses", _("Ping additional IPv4 addresses")), + ("additional_ipv6addresses", _("Ping additional IPv6 addresses")), + ("indexed_ipv4address", _("Ping IPv4 address identified by its index"), + Integer(default_value=1)), + ("indexed_ipv6address", _("Ping IPv6 address identified by its index"), + Integer(default_value=1)), + ])), + ] + check_icmp_params(), + ) + + +# Several active checks just had crit levels as one integer +def transform_cert_days(cert_days): + if not isinstance(cert_days, tuple): + return (cert_days, 0) + return cert_days + + +@rulespec_registry.register +class RulespecActiveChecksFtp(HostRulespec): + @property + def group(self): + return RulespecGroupActiveChecks + + @property + def name(self): + return "active_checks:ftp" + + @property + def match_type(self): + return "all" + + @property + def valuespec(self): + return Transform( + Dictionary(elements=[ + ("port", Integer( + title=_("Portnumber"), + default_value=21, + )), + ("response_time", + Tuple( + title=_("Expected response time"), + elements=[ + Float(title=_("Warning if above"), unit="ms", default_value=100.0), + Float(title=_("Critical if above"), unit="ms", default_value=200.0), + ])), + ("timeout", + Integer( + title=_("Seconds before connection times out"), + unit=_("sec"), + default_value=10, + )), + ("refuse_state", + DropdownChoice( + title=_("State for connection refusal"), + choices=[ + ('crit', _("CRITICAL")), + ('warn', _("WARNING")), + ('ok', _("OK")), + ])), + ("send_string", TextAscii(title=_("String to send"), size=30)), + ("expect", + ListOfStrings( + title=_("Strings to expect in response"), + orientation="horizontal", + valuespec=TextAscii(size=30), + )), + ("ssl", + FixedValue( + value=True, totext=_("use SSL"), title=_("Use SSL for the connection."))), + ( + "cert_days", + Transform( + Tuple( + title=_("SSL certificate validation"), + help=_("Minimum number of days a certificate has to be valid"), + elements=[ + Integer(title=_("Warning at or below"), minvalue=0, unit=_("days")), + Integer( + title=_("Critical at or below"), minvalue=0, unit=_("days")), + ], + ), + forth=transform_cert_days, + ), + ), + ]), + forth=lambda x: isinstance(x, tuple) and x[1] or x, + title=_("Check FTP Service"), + ) + + +@rulespec_registry.register +class RulespecActiveChecksSftp(HostRulespec): + @property + def group(self): + return RulespecGroupActiveChecks + + @property + def name(self): + return "active_checks:sftp" + + @property + def match_type(self): + return "all" + + @property + def valuespec(self): + return Tuple( + title=_("Check SFTP Service"), + help= + _("Check functionality of a SFTP server. You can use the default values for putting or getting " + "a file. This file will then be created for the test and deleted afterwards. It will of course not " + "deleted if it was not created by this active check."), + elements=[ + TextAscii(title=_("Hostname"), allow_empty=False), + TextAscii(title=_("Username"), allow_empty=False), + IndividualOrStoredPassword(title=_("Password"), allow_empty=False), + Dictionary(elements=[ + ("description", + TextAscii(title=_("Service Description"), default_value="SFTP", size=30)), + ("port", Integer(title=_("Port"), default_value=22)), + ("timeout", Integer(title=_("Timeout"), default_value=10)), + ( + "timestamp", + TextAscii( + title=_("Timestamp of a remote file"), + size=30, + help= + _("Show timestamp of a given file. You only need to specify the " + "relative path of the remote file. Examples: \'myDirectory/testfile\' " + " or 'testfile'")), + ), + ("put", + Tuple( + title=_("Put file to SFTP server"), + elements=[ + TextAscii( + title=_("Local file"), + size=30, + default_value="tmp/check_mk_testfile", + help= + _("Local path including filename. Base directory for this relative path " + "will be the home directory of your site. The testfile will be created " + "if it does not exist. Examples: \'tmp/testfile\' (file will be located in " + "$OMD_ROOT/tmp/testfile )")), + TextAscii( + title=_("Remote destination"), + size=30, + default_value="", + help= + _("Remote path where to put the file. If you leave this empty, the file will be placed " + "in the home directory of the user. Example: \'myDirectory\' ")), + ])), + ("get", + Tuple( + title=_("Get file from SFTP server"), + elements=[ + TextAscii( + title=_("Remote file"), + size=30, + default_value="check_mk_testfile", + help= + _("Remote path including filename " + "(e.g. \'testfile\'). If you also enabled " + "'Put file to SFTP server', you can use the same file for both tests." + )), + TextAscii( + title=_("Local destination"), + size=30, + default_value="tmp", + help=_("Local path where to put the downloaded file " + "(e.g. \'tmp\' ).")), + ])), + ]) + ]) + + +@rulespec_registry.register +class RulespecActiveChecksDns(HostRulespec): + @property + def group(self): + return RulespecGroupActiveChecks + + @property + def name(self): + return "active_checks:dns" + + @property + def match_type(self): + return "all" + + @property + def valuespec(self): + return Tuple( + title=_("Check DNS service"), + help=_("Check the resolution of a hostname into an IP address by a DNS server. " + "This check uses check_dns from the standard Nagios plugins."), + elements=[ + TextAscii( + title=_("Queried Hostname or IP address"), + allow_empty=False, + help=_('The name or IPv4 address you want to query')), + Dictionary( + title=_("Optional parameters"), + elements=[ + ("name", + TextUnicode( + title=_("Alternative Service description"), + help= + _("The service description will be this name instead DNS Servername" + ), + )), + ("server", + Alternative( + title=_("DNS Server"), + elements=[ + FixedValue( + value=None, + totext=_("this host"), + title=_("Use this host as a DNS server for the lookup")), + TextAscii( + title=_("Specify DNS Server"), + allow_empty=False, + help=_("Optional DNS server you want to use for the lookup")), + ])), + ( + "expected_address", + Transform( + ListOfStrings( + title=_("Expected answer (IP address or hostname)"), + help=_( + "List all allowed expected answers here. If query for an " + "IP address then the answer will be host names, that end " + "with a dot."), + ), + forth=lambda old: isinstance(old, six.string_types) and [old] or old, + ), + ), + ("expected_authority", + FixedValue( + value=True, + title=_("Expect Authoritative DNS Server"), + totext=_("Expect Authoritative"), + )), + ("response_time", + Tuple( + title=_("Expected response time"), + elements=[ + Float(title=_("Warning if above"), unit=_("sec"), default_value=1), + Float( + title=_("Critical if above"), unit=_("sec"), default_value=2), + ])), + ("timeout", + Integer( + title=_("Seconds before connection times out"), + unit=_("sec"), + default_value=10, + )), + ]), + ]) + + +@rulespec_registry.register +class RulespecActiveChecksSql(HostRulespec): + @property + def group(self): + return RulespecGroupActiveChecks + + @property + def name(self): + return "active_checks:sql" + + @property + def match_type(self): + return "all" + + @property + def valuespec(self): + return Dictionary( + title=_("Check SQL Database"), + help=_("This check connects to the specified database, sends a custom SQL-statement " + "or starts a procedure, and checks that the result has a defined format " + "containing three columns, a number, a text, and performance data. Upper or " + "lower levels may be defined here. If they are not defined the number is taken " + "as the state of the check. If a procedure is used, input parameters of the " + "procedures may by given as comma separated list. " + "This check uses the active check check_sql."), + optional_keys=["levels", "levels_low", "perfdata", "port", "procedure", "host"], + elements=[ + ("description", + TextUnicode( + title=_("Service Description"), + help=_("The name of this active service to be displayed."), + allow_empty=False, + )), + ( + "dbms", + DropdownChoice( + title=_("Type of Database"), + choices=[ + ("mysql", _("MySQL")), + ("postgres", _("PostgreSQL")), + ("mssql", _("MSSQL")), + ("oracle", _("Oracle")), + ("db2", _("DB2")), + ], + default_value="postgres", + ), + ), + ("port", + Integer( + title=_("Database Port"), + help=_('The port the DBMS listens to'), + allow_empty=True, + )), + ("name", + TextAscii( + title=_("Database Name"), + help=_('The name of the database on the DBMS'), + allow_empty=False, + )), + ("user", + TextAscii( + title=_("Database User"), + help=_('The username used to connect to the database'), + allow_empty=False, + )), + ("password", + IndividualOrStoredPassword( + title=_("Database Password"), + help=_('The password used to connect to the database'), + allow_empty=False, + )), + ("sql", + Alternative( + title=_("Query or SQL statement"), + elements=[ + TextAscii( + title=_("SQL statement or procedure name"), + help= + _('The SQL-statement or procedure name which is executed on the DBMS. It must return ' + 'a result table with one row and at least two columns. The first column must be ' + 'an integer and is interpreted as the state (0 is OK, 1 is WARN, 2 is CRIT). ' + 'Alternatively the first column can be interpreted as number value and you can ' + 'define levels for this number. The ' + 'second column is used as check output. The third column is optional and can ' + 'contain performance data.')), + UploadOrPasteTextFile( + title=_("Import Query"), + file_title=_("File including Query"), + default_mode="upload", + ), + ], + allow_empty=False, + )), + ( + "procedure", + Dictionary( + optional_keys=["input"], + title=_("Use procedure call instead of SQL statement"), + help=_("If you activate this option, a name of a stored " + "procedure is used instead of an SQL statement. " + "The procedure should return one output variable, " + "which is evaluated in the check. If input parameters " + "are required, they may be specified below."), + elements=[ + ("useprocs", FixedValue( + value=True, + totext=_("procedure call is used"), + )), + ("input", + TextAscii( + title=_("Input Parameters"), + allow_empty=True, + help=_( + "Input parameters, if required by the database procedure. " + "If several parameters are required, use commas to separate them." + ), + )), + ]), + ), + ("levels", + Tuple( + title=_("Upper levels for first output item"), + elements=[ + Float(title=_("Warning if above")), + Float(title=_("Critical if above")) + ])), + ("levels_low", + Tuple( + title=_("Lower levels for first output item"), + elements=[ + Float(title=_("Warning if below")), + Float(title=_("Critical if below")) + ])), + ("perfdata", + FixedValue( + title=_("Performance Data"), + totext=_("Store output value into RRD database"), + value=True, + )), + ("host", + TextAscii( + title=_("DNS hostname or IP address"), + help=_("This defaults to the host for which the active check is configured."), + )), + ]) + + +@rulespec_registry.register +class RulespecActiveChecksTcp(HostRulespec): + @property + def group(self): + return RulespecGroupActiveChecks + + @property + def name(self): + return "active_checks:tcp" + + @property + def match_type(self): + return "all" + + @property + def valuespec(self): + return Tuple( + title=_("Check connecting to a TCP port"), + help=_("This check tests the connection to a TCP port. It uses " + "check_tcp from the standard Nagios plugins."), + elements=[ + Integer(title=_("TCP Port"), minvalue=1, maxvalue=65535), + Dictionary( + title=_("Optional parameters"), + elements=[ + ("svc_description", + TextUnicode( + title=_("Service description"), + allow_empty=False, + help=_( + "Here you can specify a service description. " + "If this parameter is not set, the service is named TCP Port [PORT NUMBER]" + ))), + ("hostname", + TextAscii( + title=_("DNS Hostname"), + allow_empty=False, + help=_("If you specify a hostname here, then a dynamic DNS lookup " + "will be done instead of using the IP address of the host " + "as configured in your host properties."))), + ("response_time", + Tuple( + title=_("Expected response time"), + elements=[ + Float(title=_("Warning if above"), unit="ms", default_value=100.0), + Float( + title=_("Critical if above"), unit="ms", default_value=200.0), + ])), + ("timeout", + Integer( + title=_("Seconds before connection times out"), + unit=_("sec"), + default_value=10, + )), + ("refuse_state", + DropdownChoice( + title=_("State for connection refusal"), + choices=[ + ('crit', _("CRITICAL")), + ('warn', _("WARNING")), + ('ok', _("OK")), + ])), + ("send_string", TextAscii(title=_("String to send"), size=30)), + ("escape_send_string", + FixedValue( + value=True, + title= + _("Expand \\n, \\r and \\t in the sent string" + ), + totext=_("expand escapes"))), + ("expect", + ListOfStrings( + title=_("Strings to expect in response"), + orientation="horizontal", + valuespec=TextAscii(size=30), + )), + ("expect_all", + FixedValue( + value=True, + totext=_("expect all"), + title=_("Expect all of those strings in the response"))), + ("jail", + FixedValue( + value=True, + title=_("Hide response from socket"), + help=_("As soon as you configure expected strings in " + "the response the check will output the response - " + "as long as you do not hide it with this option"), + totext=_("hide response"))), + ("mismatch_state", + DropdownChoice( + title=_("State for expected string mismatch"), + choices=[ + ('crit', _("CRITICAL")), + ('warn', _("WARNING")), + ('ok', _("OK")), + ])), + ("delay", + Integer( + title=_("Seconds to wait before polling"), + help=_( + "Seconds to wait between sending string and polling for response"), + unit=_("sec"), + default_value=0, + )), + ( + "maxbytes", + Integer( + title=_("Maximum number of bytes to receive"), + help=_("Close connection once more than this number of " + "bytes are received. Per default the number of " + "read bytes is not limited. This setting is only " + "used if you expect strings in the response."), + default_value=1024, + ), + ), + ("ssl", + FixedValue( + value=True, + totext=_("use SSL"), + title=_("Use SSL for the connection."))), + ( + "cert_days", + Transform( + Tuple( + title=_("SSL certificate validation"), + help=_("Minimum number of days a certificate has to be valid"), + elements=[ + Integer( + title=_("Warning at or below"), + minvalue=0, + unit=_("days")), + Integer( + title=_("Critical at or below"), + minvalue=0, + unit=_("days")), + ], + ), + forth=transform_cert_days, + ), + ), + ("quit_string", + TextAscii( + title=_("Final string to send"), + help=_("String to send server to initiate a clean close of " + "the connection"), + size=30)), + ]), + ]) + + +@rulespec_registry.register +class RulespecActiveChecksUniserv(HostRulespec): + @property + def group(self): + return RulespecGroupActiveChecks + + @property + def name(self): + return "active_checks:uniserv" + + @property + def valuespec(self): + return Dictionary( + title=_("Check uniserv service"), + optional_keys=False, + elements=[ + ("port", Integer(title=_("Port"))), + ("service", + TextAscii( + title=_("Service Name"), + help= + _("Enter the uniserve service name here (has nothing to do with service description)." + ))), + ("job", + CascadingDropdown( + title=_("Mode of the Check"), + help=_("Choose, whether you just want to query the version number," + " or if you want to check the response to an address query."), + choices=[ + ("version", _("Check for Version")), + ("address", _("Check for an Address"), + Dictionary( + title=_("Address Check mode"), + optional_keys=False, + elements=[ + ("street", TextAscii(title=_("Street name"))), + ("street_no", Integer(title=_("Street number"))), + ("city", TextAscii(title=_("City name"))), + ("search_regex", + TextAscii( + title=_("Check City against Regex"), + help=_( + "The city name from the response will be checked against " + "the regular expression specified here"), + )), + ])), + ])), + ]) + + +def _ip_address_family_element(): + return ( + "address_family", + DropdownChoice( + title=_("IP Address Family"), + choices=[ + (None, _("Primary Address Family")), + ('ipv4', _("Enforce IPv4")), + ('ipv6', _("Enforce IPv6")), + ], + default_value=None), + ) + + +@rulespec_registry.register +class RulespecActiveChecksHttp(HostRulespec): + @property + def group(self): + return RulespecGroupActiveChecks + + @property + def name(self): + return "active_checks:http" + + @property + def match_type(self): + return "all" + + @property + def valuespec(self): + return Tuple( + title=_("Check HTTP service"), + help=_("Check HTTP/HTTPS service using the plugin check_http " + "from the standard Monitoring Plugins. " + "This plugin tests the HTTP service on the specified host. " + "It can test normal (HTTP) and secure (HTTPS) servers, follow " + "redirects, search for strings and regular expressions, check " + "connection times, and report on certificate expiration times."), + elements=[ + TextUnicode( + title=_("Name"), + help=_( + "Will be used in the service description. If the name starts with " + "a caret (^), the service description will not be prefixed with either " + "HTTP or HTTPS."), + allow_empty=False), + Alternative( + title=_("Mode of the Check"), + help=_("Perform a check of the URL or the certificate expiration."), + elements=[ + Dictionary( + title=_("Check the URL"), + elements=[ + ("virthost", + Tuple( + title=_("Virtual host"), + elements=[ + TextAscii( + title=_("Name of the virtual host"), + help= + _("Set this in order to specify the name of the " + "virtual host for the query (using HTTP/1.1). If you " + "leave this empty, then the IP address of the host " + "will be used instead."), + allow_empty=False), + Checkbox( + label=_("Omit specifying an IP address"), + help= + _("Usually Check_MK will nail this check to the " + "IP address of the host it is attached to. With this " + "option you can have the check use the name of the " + "virtual host instead and do a dynamic DNS lookup."), + true_label=_("omit IP address"), + false_label=_("specify IP address"), + ), + ])), + ("uri", + TextAscii( + title=_("URI to fetch (default is /)"), + allow_empty=False, + default_value="/")), + ("port", + Integer( + title=_("TCP Port"), + minvalue=1, + maxvalue=65535, + default_value=80)), + _ip_address_family_element(), + ("ssl", + Transform( + DropdownChoice( + title=_("Use SSL/HTTPS for the connection"), + choices=[ + ("auto", _("Use SSL with auto negotiation")), + ("1.2", _("Use SSL, enforce TLSv1.2")), + ("1.1", _("Use SSL, enforce TLSv1.1")), + ("1", _("Use SSL, enforce TLSv1")), + ("2", _("Use SSL, enforce SSLv2")), + ("3", _("Use SSL, enforce SSLv3")), + ], + default_value="auto", + ), + forth=lambda x: x is True and "auto" or x, + )), + ("sni", + FixedValue( + value=True, + totext=_("enable SNI"), + title=_("Enable SSL/TLS hostname extension support (SNI)"), + )), + ("response_time", + Tuple( + title=_("Expected response time"), + elements=[ + Float( + title=_("Warning if above"), + unit="ms", + default_value=100.0), + Float( + title=_("Critical if above"), + unit="ms", + default_value=200.0), + ])), + ("timeout", + Integer( + title=_("Seconds before connection times out"), + unit=_("sec"), + default_value=10, + )), + ( + "user_agent", + TextAscii( + title=_("User Agent"), + help=_( + "String to be sent in http header as \"User Agent\""), + allow_empty=False, + ), + ), + ( + "add_headers", + ListOfStrings( + title=_("Additional header lines"), + orientation="vertical", + valuespec=TextAscii(size=40), + ), + ), + ("auth", + Tuple( + title=_("Authorization"), + help=_("Credentials for HTTP Basic Authentication"), + elements=[ + TextAscii(title=_("Username"), size=12, allow_empty=False), + IndividualOrStoredPassword(title=_("Password"),) + ])), + ( + "proxy", + TextAscii( + title=_("Proxy host"), + help=_( + "To use a proxy you have to use the Port of the proxy, " + "specify the virtual host and the URL to fetch, " + "use the HTTP Method CONNECT, and use SSL/HTTPS " + "for the connection")), + ), + ("proxy_auth", + Tuple( + title=_("Proxy-Authorization"), + help=_("Credentials for HTTP Proxy with basic authentication"), + elements=[ + TextAscii(title=_("Username"), size=12, allow_empty=False), + IndividualOrStoredPassword(title=_("Password"),), + ])), + ( + "onredirect", + DropdownChoice( + title=_("How to handle redirect"), + choices=[ + ('ok', _("Make check OK")), + ('warning', _("Make check WARNING")), + ('critical', _("Make check CRITICAL")), + ('follow', _("Follow the redirection")), + ('sticky', _("Follow, but stay to same IP address")), + ('stickyport', + _("Follow, but stay to same IP-address and port")), + ], + default_value='follow'), + ), + ("expect_response_header", + TextAscii(title=_("String to expect in response headers"),)), + ("expect_response", + ListOfStrings( + title=_("Strings to expect in server response"), + help=_("At least one of these strings is expected in " + "the first (status) line of the server response " + "(default: HTTP/1.). If specified skips " + "all other status line logic (ex: 3xx, 4xx, 5xx " + "processing)"), + )), + ("expect_string", + TextUnicode( + title=_("Fixed string to expect in the content"), + allow_empty=False, + )), + ( + "expect_regex", + Transform( + Tuple( + orientation="vertical", + show_titles=False, + elements=[ + RegExp( + label=_("Regular expression: "), + mode=RegExp.infix, + ), + Checkbox(label=_("Case insensitive")), + Checkbox( + label=_("return CRITICAL if found, OK if not")), + Checkbox(label=_("Multiline string matching")), + ]), + forth= + lambda x: len(x) == 3 and tuple(list(x) + [False]) or x, + title=_("Regular expression to expect in content"), + ), + ), + ("post_data", + Tuple( + title=_("Send HTTP POST data"), + elements=[ + TextUnicode( + title=_("HTTP POST data"), + help=_( + "Data to send via HTTP POST method. " + "Please make sure, that the data is URL-encoded."), + size=40, + ), + TextAscii( + title=_("Content-Type"), default_value="text/html"), + ])), + ("method", + DropdownChoice( + title=_("HTTP Method"), + default_value="GET", + choices=[ + ("GET", "GET"), + ("POST", "POST"), + ("OPTIONS", "OPTIONS"), + ("TRACE", "TRACE"), + ("PUT", "PUT"), + ("DELETE", "DELETE"), + ("HEAD", "HEAD"), + ("CONNECT", "CONNECT"), + ("PROPFIND", "PROPFIND"), + ])), + ("no_body", + FixedValue( + value=True, + title=_("Don't wait for document body"), + help=_( + "Note: this still does an HTTP GET or POST, not a HEAD."), + totext=_("don't wait for body"))), + ("page_size", + Tuple( + title=_("Page size to expect"), + elements=[ + Integer(title=_("Minimum"), unit=_("Bytes")), + Integer(title=_("Maximum"), unit=_("Bytes")), + ])), + ("max_age", + Age( + title=_("Maximum age"), + help=_("Warn, if the age of the page is older than this"), + default_value=3600 * 24, + )), + ("urlize", + FixedValue( + value=True, + title=_("Clickable URLs"), + totext=_("Format check output as hyperlink"), + help=_( + "With this option the check produces an output that is a valid hyperlink " + "to the checked URL and this clickable."), + )), + ("extended_perfdata", + FixedValue( + value=True, + totext=_("Extended perfdata"), + title=_("Record additional performance data"), + help= + _("This option makes the HTTP check produce more detailed performance data values " + "like the connect time, header time, time till first byte received and the " + "transfer time."), + )), + ("verbose", + FixedValue( + value=True, + title=_("Verbose output"), + totext=_("Give verbose output"), + )), + ]), + Dictionary( + title=_("Check SSL Certificate Age"), + elements=[ + ( + "cert_days", + Transform( + Tuple( + title=_("Age"), + help= + _("Minimum number of days a certificate has to be valid. " + "Port defaults to 443. When this option is used the URL " + "is not checked."), + elements=[ + Integer( + title=_("Warning at or below"), + minvalue=0, + unit=_("days")), + Integer( + title=_("Critical at or below"), + minvalue=0, + unit=_("days")), + ], + ), + forth=transform_cert_days, + ), + ), + ( + "cert_host", + TextAscii( + title=_("Check Certificate of different IP / DNS Name"), + help= + _("For each SSL certificate on a host, a different IP address is needed. " + "Here, you can specify the address if it differs from the " + "address from the host primary address."), + ), + ), + ( + "port", + Integer( + title=_("TCP Port"), + minvalue=1, + maxvalue=65535, + default_value=443, + ), + ), + _ip_address_family_element(), + ( + "sni", + FixedValue( + value=True, + totext=_("enable SNI"), + title=_("Enable SSL/TLS hostname extension support (SNI)"), + ), + ), + ( + "proxy", + TextAscii( + title=_("Proxy host"), + help= + _("To use a proxy you have to specify the Port of the proxy. " + )), + ), + ("proxy_auth", + Tuple( + title=_("Proxy-Authorization"), + help=_("Credentials for HTTP Proxy with basic authentication"), + elements=[ + TextAscii(title=_("Username"), size=12, allow_empty=False), + IndividualOrStoredPassword(title=_("Password"),), + ])), + ], + required_keys=["cert_days"], + ), + ]), + ]) + + +@rulespec_registry.register +class RulespecActiveChecksLdap(HostRulespec): + @property + def group(self): + return RulespecGroupActiveChecks + + @property + def name(self): + return "active_checks:ldap" + + @property + def match_type(self): + return "all" + + @property + def valuespec(self): + return Tuple( + title=_("Check access to LDAP service"), + help=_("This check uses check_ldap from the standard " + "Nagios plugins in order to try the response of an LDAP " + "server."), + elements=[ + TextUnicode( + title=_("Name"), + help= + _("The service description will be LDAP plus this name. If the name starts with " + "a caret (^), the service description will not be prefixed with LDAP." + ), + allow_empty=False), + TextAscii( + title=_("Base DN"), + help=_("LDAP base, e.g. ou=Development, o=Mathias Kettner GmbH, c=de"), + allow_empty=False, + size=60), + Dictionary( + title=_("Optional parameters"), + elements=[ + ("attribute", + TextAscii( + title=_("Attribute to search"), + help=_("LDAP attribute to search, " + "The default is (objectclass=*)."), + size=40, + allow_empty=False, + default_value="(objectclass=*)", + )), + ("authentication", + Tuple( + title=_("Authentication"), + elements=[ + TextAscii( + title=_("Bind DN"), + help=_("Distinguished name for binding"), + allow_empty=False, + size=60, + ), + Password( + title=_("Password"), + help= + _("Password for binding, if your server requires an authentication" + ), + allow_empty=False, + size=20, + ) + ])), + ("port", + Integer( + title=_("TCP Port"), + help=_( + "Default is 389 for normal connections and 636 for SSL connections." + ), + minvalue=1, + maxvalue=65535, + default_value=389)), + ("ssl", + FixedValue( + value=True, + totext=_("Use SSL"), + title=_("Use LDAPS (SSL)"), + help= + _("Use LDAPS (LDAP SSLv2 method). This sets the default port number to 636" + ))), + ("hostname", + TextAscii( + title=_("Alternative Hostname"), + help= + _("Use a alternative field as Hostname in case of SSL Certificate Problems (eg. the Hostalias )" + ), + size=40, + allow_empty=False, + default_value="$HOSTALIAS$", + )), + ("version", + DropdownChoice( + title=_("LDAP Version"), + help=_("The default is to use version 2"), + choices=[ + ("v2", _("Version 2")), + ("v3", _("Version 3")), + ("v3tls", _("Version 3 and TLS")), + ], + default_value="v2", + )), + ("response_time", + Tuple( + title=_("Expected response time"), + elements=[ + Float( + title=_("Warning if above"), unit="ms", default_value=1000.0), + Float( + title=_("Critical if above"), unit="ms", default_value=2000.0), + ])), + ("timeout", + Integer( + title=_("Seconds before connection times out"), + unit=_("sec"), + default_value=10, + )), + ]) + ]) + + +@rulespec_registry.register +class RulespecActiveChecksSmtp(HostRulespec): + @property + def group(self): + return RulespecGroupActiveChecks + + @property + def name(self): + return "active_checks:smtp" + + @property + def match_type(self): + return "all" + + @property + def valuespec(self): + return Tuple( + title=_("Check access to SMTP services"), + help=_("This check uses check_smtp from the standard " + "Nagios plugins in order to try the response of an SMTP " + "server."), + elements=[ + TextUnicode( + title=_("Name"), + help= + _("The service description will be SMTP plus this name. If the name starts with " + "a caret (^), the service description will not be prefixed with SMTP." + ), + allow_empty=False), + Transform( + Dictionary( + title=_("Optional parameters"), + elements=[ + ("hostname", + TextAscii( + title=_("DNS Hostname or IP address"), + allow_empty=False, + help=_( + "You can specify a hostname or IP address different from the IP address " + "of the host as configured in your host properties."))), + ("port", + Transform( + Integer( + title=_("TCP Port to connect to"), + help=_("The TCP Port the SMTP server is listening on. " + "The default is 25."), + size=5, + minvalue=1, + maxvalue=65535, + default_value="25", + ), + forth=int, + )), + _ip_address_family_element(), + ("expect", + TextAscii( + title=_("Expected String"), + help=_("String to expect in first line of server response. " + "The default is 220."), + size=8, + allow_empty=False, + default_value="220", + )), + ('commands', + ListOfStrings( + title=_("SMTP Commands"), + help=_("SMTP commands to execute."), + )), + ('command_responses', + ListOfStrings( + title=_("SMTP Responses"), + help=_("Expected responses to the given SMTP commands."), + )), + ("from", + TextAscii( + title=_("FROM-Address"), + help= + _("FROM-address to include in MAIL command, required by Exchange 2000" + ), + size=20, + allow_empty=True, + default_value="", + )), + ("fqdn", + TextAscii( + title=_("FQDN"), + help=_("FQDN used for HELO"), + size=20, + allow_empty=True, + default_value="", + )), + ("cert_days", + Transform( + Tuple( + title=_("Minimum Certificate Age"), + help=_("Minimum number of days a certificate has to be valid"), + elements=[ + Integer( + title=_("Warning at or below"), + minvalue=0, + unit=_("days")), + Integer( + title=_("Critical at or below"), + minvalue=0, + unit=_("days")), + ], + ), + forth=transform_cert_days, + )), + ("starttls", + FixedValue( + True, + totext=_("STARTTLS enabled."), + title=_("Use STARTTLS for the connection."))), + ("auth", + Tuple( + title=_("Enable SMTP AUTH (LOGIN)"), + help=_( + "SMTP AUTH type to check (default none, only LOGIN supported)" + ), + elements=[ + TextAscii(title=_("Username"), size=12, allow_empty=False), + Password(title=_("Password"), size=12, allow_empty=False), + ])), + ("response_time", + Tuple( + title=_("Expected response time"), + elements=[ + Integer(title=_("Warning if above"), unit=_("sec")), + Integer(title=_("Critical if above"), unit=_("sec")), + ])), + ("timeout", + Integer( + title=_("Seconds before connection times out"), + unit=_("sec"), + default_value=10, + )), + ]), + forth=self._transform_smtp_address_family, + ) + ]) + + def _transform_smtp_address_family(self, val): + if "ip_version" in val: + val["address_family"] = val.pop("ip_version") + return val + + +@rulespec_registry.register +class RulespecActiveChecksDiskSmb(HostRulespec): + @property + def group(self): + return RulespecGroupActiveChecks + + @property + def name(self): + return "active_checks:disk_smb" + + @property + def match_type(self): + return "all" + + @property + def valuespec(self): + return Dictionary( + title=_("Check access to SMB share"), + help=_("This ruleset helps you to configure the classical Nagios " + "plugin check_disk_smb that checks the access to " + "filesystem shares that are exported via SMB/CIFS."), + elements=[ + ("share", + TextUnicode( + title=_("SMB share to check"), + help=_( + "Enter the plain name of the share only, e. g. iso, not " + "the full UNC like \\\\servername\\iso"), + size=32, + allow_empty=False, + )), + ("workgroup", + TextUnicode( + title=_("Workgroup"), + help=_("Workgroup or domain used (defaults to WORKGROUP)"), + size=32, + allow_empty=False, + )), + ("host", + TextAscii( + title=_("NetBIOS name of the server"), + help=_("If omitted then the IP address is being used."), + size=32, + allow_empty=False, + )), + ("port", + Integer( + title=_("TCP Port"), + help=_("TCP port number to connect to. Usually either 139 or 445."), + default_value=445, + minvalue=1, + maxvalue=65535, + )), + ("levels", + Tuple( + title=_("Levels for used disk space"), + elements=[ + Percentage(title=_("Warning if above"), default_value=85, allow_int=True), + Percentage(title=_("Critical if above"), default_value=95, allow_int=True), + ])), + ("auth", + Tuple( + title=_("Authorization"), + elements=[ + TextAscii(title=_("Username"), allow_empty=False, size=24), + Password(title=_("Password"), allow_empty=False, size=12), + ], + )), + ], + required_keys=["share", "levels"], + ) + + +@rulespec_registry.register +class RulespecCustomChecks(HostRulespec): + @property + def group(self): + return RulespecGroupActiveChecks + + @property + def name(self): + return "custom_checks" + + @property + def match_type(self): + return "all" + + @property + def valuespec(self): + return Dictionary( + title=_("Classical active and passive Monitoring checks"), + help=_("With this ruleset you can configure "classical Monitoring checks" " + "to be executed directly on your monitoring server. These checks " + "will not use Check_MK. It is also possible to configure passive " + "checks that are fed with data from external sources via the " + "command pipe of the monitoring core."), + elements=[ + ("service_description", + TextUnicode( + title=_("Service description"), + help=_("Please make sure that this is unique per host " + "and does not collide with other services."), + allow_empty=False, + default_value=_("Customcheck"))), + ( + "command_line", + PluginCommandLine(), + ), + ("command_name", + TextAscii( + title=_("Internal command name"), + help=_("If you want, you can specify a name that will be used " + "in the define command section for these checks. This " + "allows you to a assign a custom PNP template for the performance " + "data of the checks. If you omit this, then check-mk-custom " + "will be used."), + size=32)), + ("has_perfdata", + FixedValue( + title=_("Performance data"), + value=True, + totext=_("process performance data"), + )), + ("freshness", + Dictionary( + title=_("Check freshness"), + help= + _("Freshness checking is only useful for passive checks when the staleness feature " + "is not enough for you. It changes the state of a check to a configurable other state " + "when the check results are not arriving in time. Staleness will still grey out the " + "test after the corrsponding interval. If you don't want that, you might want to adjust " + "the staleness interval as well. The staleness interval is calculated from the normal " + "check interval multiplied by the staleness value in the Global Settings. " + "The normal check interval can be configured in a separate rule for your check." + ), + optional_keys=False, + elements=[ + ("interval", + Integer( + title=_("Expected update interval"), + label=_("Updates are expected at least every"), + unit=_("minutes"), + minvalue=1, + default_value=10, + )), + ("state", + DropdownChoice( + title=_("State in case of absent updates"), + choices=[ + (1, _("WARN")), + (2, _("CRIT")), + (3, _("UNKNOWN")), + ], + default_value=3, + )), + ("output", + TextUnicode( + title=_("Plugin output in case of absent updates"), + size=40, + allow_empty=False, + default_value=_("Check result did not arrive in time"))), + ], + )), + ], + required_keys=["service_description"], + ) + + +@rulespec_registry.register +class RulespecActiveChecksBiAggr(HostRulespec): + @property + def group(self): + return RulespecGroupActiveChecks + + @property + def name(self): + return "active_checks:bi_aggr" + + @property + def match_type(self): + return "all" + + @property + def valuespec(self): + return Tuple( + title=_("Check State of BI Aggregation"), + help=_( + "Connect to the local or a remote monitoring host, which uses Check_MK BI to aggregate " + "several states to a single BI aggregation, which you want to show up as a single " + "service."), + elements=[ + TextAscii( + title=_("Base URL (OMD Site)"), + help= + _("The base URL to the monitoring instance. For example http://mycheckmk01/mysite. " + "You can use macros like $HOSTADDRESS$ and $HOSTNAME$ within this URL to " + "make them be replaced by the hosts values."), + size=60, + allow_empty=False), + TextAscii( + title=_("Aggregation Name"), + help= + _("The name of the aggregation to fetch. It will be added to the service description. You can " + "use macros like $HOSTADDRESS$ and $HOSTNAME$ within this parameter to " + "make them be replaced by the hosts values. The aggregation name is the title in the " + "top-level-rule of your BI pack."), + allow_empty=False), + TextAscii( + title=_("Username"), + help= + _("The name of the user account to use for fetching the BI aggregation via HTTP. When " + "using the cookie based authentication mode (default), this must be a user where " + "authentication is set to \"Automation Secret\" based authentication."), + allow_empty=False), + IndividualOrStoredPassword( + title=_("Password / Secret"), + help=_( + "Valid automation secret or password for the user, depending on the chosen " + "authentication mode. Be aware that this mode has to be enabled on the monitoring instance. " + "Otherwise authentication will fail."), + allow_empty=False), + Dictionary( + title=_("Optional parameters"), + elements=[ + ("auth_mode", + DropdownChoice( + title=_('Authentication Mode'), + default_value='cookie', + choices=[ + ('cookie', _('Form (Cookie) based')), + ('basic', _('HTTP Basic')), + ('digest', _('HTTP Digest')), + ('kerberos', _('Kerberos')), + ], + )), + ("timeout", + Integer( + title=_("Seconds before connection times out"), + unit=_("sec"), + default_value=60, + )), + ("in_downtime", + RadioChoice( + title=_("State, if BI aggregate is in scheduled downtime"), + orientation="vertical", + choices=[ + (None, _("Use normal state, ignore downtime")), + ("ok", _("Force to be OK")), + ("warn", _("Force to be WARN, if aggregate is not OK")), + ])), + ("acknowledged", + RadioChoice( + title=_("State, if BI aggregate is acknowledged"), + orientation="vertical", + choices=[ + (None, _("Use normal state, ignore acknowledgement")), + ("ok", _("Force to be OK")), + ("warn", _("Force to be WARN, if aggregate is not OK")), + ])), + ("track_downtimes", + Checkbox( + title=_("Track downtimes"), + label=_("Automatically track downtimes of aggregation"), + help=_( + "If this is active, the check will automatically go into downtime " + "whenever the aggregation does. This downtime is also cleaned up " + "automatically when the aggregation leaves downtime. " + "Downtimes you set manually for this check are unaffected."), + )), + ]), + ]) + + +@rulespec_registry.register +class RulespecActiveChecksFormSubmit(HostRulespec): + @property + def group(self): + return RulespecGroupActiveChecks + + @property + def name(self): + return "active_checks:form_submit" + + @property + def match_type(self): + return "all" + + @property + def valuespec(self): + return Tuple( + title=_("Check HTML Form Submit"), + help= + _("Check submission of HTML forms via HTTP/HTTPS using the plugin check_form_submit " + "provided with Check_MK. This plugin provides more functionality as check_http, " + "as it automatically follows HTTP redirect, accepts and uses cookies, parses forms " + "from the requested pages, changes vars and submits them to check the response " + "afterwards."), + elements=[ + TextUnicode( + title=_("Name"), + help=_("The name will be used in the service description"), + allow_empty=False), + Dictionary( + title=_("Check the URL"), + elements=[ + ("hosts", + ListOfStrings( + title=_('Check specific host(s)'), + help=_( + 'By default, if you do not specify any host addresses here, ' + 'the host address of the host this service is assigned to will ' + 'be used. But by specifying one or several host addresses here, ' + 'it is possible to let the check monitor one or multiple hosts.')) + ), + ("virthost", + TextAscii( + title=_("Virtual host"), + help=_("Set this in order to specify the name of the " + "virtual host for the query (using HTTP/1.1). When you " + "leave this empty, then the IP address of the host " + "will be used instead."), + allow_empty=False, + )), + ("uri", + TextAscii( + title=_("URI to fetch (default is /)"), + allow_empty=False, + default_value="/", + regex='^/.*', + )), + ("port", + Integer( + title=_("TCP Port"), + minvalue=1, + maxvalue=65535, + default_value=80, + )), + ("ssl", + FixedValue( + value=True, + totext=_("use SSL/HTTPS"), + title=_("Use SSL/HTTPS for the connection."))), + ("timeout", + Integer( + title=_("Seconds before connection times out"), + unit=_("sec"), + default_value=10, + )), + ("expect_regex", + RegExp( + title=_("Regular expression to expect in content"), + mode=RegExp.infix, + )), + ("form_name", + TextAscii( + title=_("Name of the form to populate and submit"), + help=_("If there is only one form element on the requested page, you " + "do not need to provide the name of that form here. But if you " + "have several forms on that page, you need to provide the name " + "of the form here, to enable the check to identify the correct " + "form element."), + allow_empty=True, + )), + ("query", + TextAscii( + title=_("Send HTTP POST data"), + help=_( + "Data to send via HTTP POST method. Please make sure, that the data " + "is URL-encoded (for example \"key1=val1&key2=val2\")."), + size=40, + )), + ("num_succeeded", + Tuple( + title=_("Multiple Hosts: Number of successful results"), + elements=[ + Integer(title=_("Warning if equal or below")), + Integer(title=_("Critical if equal or below")), + ])), + ]), + ]) + + +@rulespec_registry.register +class RulespecActiveChecksNotifyCount(HostRulespec): + @property + def group(self): + return RulespecGroupActiveChecks + + @property + def name(self): + return "active_checks:notify_count" + + @property + def match_type(self): + return "all" + + @property + def valuespec(self): + return Tuple( + title=_("Check Number of Notifications per Contact"), + help= + _("Check the number of sent notifications per contact using the plugin check_notify_count " + "provided with Check_MK. This plugin counts the total number of notifications sent by the local " + "monitoring core and creates graphs for each individual contact. You can configure thresholds " + "on the number of notifications per contact in a defined time interval. " + "This plugin queries livestatus to extract the notification related log entries from the " + "log file of your monitoring core."), + elements=[ + TextUnicode( + title=_("Service Description"), + help=_("The name that will be used in the service description"), + allow_empty=False), + Integer( + title=_("Interval to monitor"), + label=_("notifications within last"), + unit=_("minutes"), + minvalue=1, + default_value=60, + ), + Dictionary( + title=_("Optional parameters"), + elements=[ + ("num_per_contact", + Tuple( + title=_("Thresholds for Notifications per Contact"), + elements=[ + Integer(title=_("Warning if above"), default_value=20), + Integer(title=_("Critical if above"), default_value=50), + ])), + ]), + ]) + + +@rulespec_registry.register +class RulespecActiveChecksTraceroute(HostRulespec): + @property + def group(self): + return RulespecGroupActiveChecks + + @property + def name(self): + return "active_checks:traceroute" + + @property + def match_type(self): + return "all" + + @property + def valuespec(self): + return Dictionary( + title=_("Check current routing (uses traceroute)"), + help=_( + "This active check uses traceroute in order to determine the current " + "routing from the monitoring host to the target host. You can specify any number " + "of missing or expected routes in that way detect e.g. an (unintended) failover " + "to a secondary route."), + elements=[ + ("dns", + Checkbox( + title=_("Name resolution"), + label=_("Use DNS to convert IP addresses into hostnames"), + help=_("If you use this option, then traceroute is not being " + "called with the option -n. That means that all IP addresses " + "are tried to be converted into names. This usually adds additional " + "execution time. Also DNS resolution might fail for some addresses."), + )), + ("routers", + ListOf( + Tuple(elements=[ + TextAscii( + title=_("Router (FQDN, IP-Address)"), + allow_empty=False, + ), + DropdownChoice( + title=_("How"), + choices=[ + ('W', _("WARN - if this router is not being used")), + ('C', _("CRIT - if this router is not being used")), + ('w', _("WARN - if this router is being used")), + ('c', _("CRIT - if this router is being used")), + ]), + ]), + title=_("Router that must or must not be used"), + add_label=_("Add Condition"), + )), + ("method", + DropdownChoice( + title=_("Method of probing"), + choices=[ + (None, _("UDP (default behaviour of tcpdump)")), + ("icmp", _("ICMP Echo Request")), + ("tcp", _("TCP SYN")), + ])), + ], + optional_keys=False, + ) + + +@rulespec_registry.register +class RulespecActiveChecksMailLoop(HostRulespec): + @property + def group(self): + return RulespecGroupActiveChecks + + @property + def name(self): + return "active_checks:mail_loop" + + @property + def match_type(self): + return "all" + + @property + def valuespec(self): + return Dictionary( + title=_('Check Email Delivery'), + help=_( + 'This active check sends out special E-Mails to a defined mail address using ' + 'the SMTP protocol and then tries to receive these mails back by querying the ' + 'inbox of a IMAP or POP3 mailbox. With this check you can verify that your whole ' + 'mail delivery progress is working.'), + optional_keys=[ + 'subject', 'smtp_server', 'smtp_tls', 'smtp_port', 'smtp_auth', 'imap_tls', + 'connect_timeout', 'delete_messages', 'duration' + ], + elements=[ + ('item', + TextUnicode( + title=_('Name'), + help=_('The service description will be Mail Loop plus this name'), + allow_empty=False)), + ('subject', + TextAscii( + title=_('Subject'), + allow_empty=False, + help=_('Here you can specify the subject text ' + 'instead of default text \'Check_MK-Mail-Loop\'.'), + )), + ('smtp_server', + TextAscii( + title=_('SMTP Server'), + allow_empty=False, + help=_( + 'You can specify a hostname or IP address different from the IP address ' + 'of the host this check will be assigned to.'))), + ('smtp_tls', + FixedValue( + True, + title=_('Use TLS over SMTP'), + totext=_('Encrypt SMTP communication using TLS'), + )), + ('imap_tls', + FixedValue( + True, + title=_('Use TLS for IMAP authentification'), + totext=_('IMAP authentification uses TLS'), + )), + ('smtp_port', + Integer( + title=_('SMTP TCP Port to connect to'), + help=_( + 'The TCP Port the SMTP server is listening on. Defaulting to 25.' + ), + allow_empty=False, + default_value=25, + )), + ('smtp_auth', + Tuple( + title=_('SMTP Authentication'), + elements=[ + TextAscii(title=_('Username'), allow_empty=False, size=24), + IndividualOrStoredPassword( + title=_('Password'), allow_empty=False, size=12), + ], + )), + ] + _mail_receiving_params() + [ + ('mail_from', EmailAddress(title=_('From: email address'),)), + ('mail_to', EmailAddress(title=_('Destination email address'),)), + ('connect_timeout', + Integer( + title=_('Connect Timeout'), + minvalue=1, + default_value=10, + unit=_('sec'), + )), + ("duration", + Tuple( + title=_("Loop duration"), + elements=[ + Age(title=_("Warning at")), + Age(title=_("Critical at")), + ])), + ('delete_messages', + FixedValue( + True, + title=_('Delete processed messages'), + totext=_('Delete all processed message belonging to this check'), + help=_('Delete all messages identified as being related to this ' + 'check. This is disabled by default, which will make ' + 'your mailbox grow when you not clean it up on your own.'), + )), + ]) + + +@rulespec_registry.register +class RulespecActiveChecksMail(HostRulespec): + @property + def group(self): + return RulespecGroupActiveChecks + + @property + def name(self): + return "active_checks:mail" + + @property + def match_type(self): + return "all" + + @property + def valuespec(self): + return Dictionary( + title=_('Check Email'), + help=_('The basic function of this check is to log in into an IMAP or POP3 mailbox to ' + 'monitor whether or not the login is possible. A extended feature is, that the ' + 'check can fetch all (or just some) from the mailbox and forward them as events ' + 'to the Event Console.'), + required_keys=['service_description', 'fetch'], + elements=[('service_description', + TextUnicode( + title=_('Service description'), + help=_('Please make sure that this is unique per host ' + 'and does not collide with other services.'), + allow_empty=False, + default_value="Email"))] + _mail_receiving_params() + + [ + ('connect_timeout', + Integer( + title=_('Connect Timeout'), + minvalue=1, + default_value=10, + unit=_('sec'), + )), + ( + 'forward', + Dictionary( + title=_("Forward mails as events to Event Console"), + elements=[ + ( + 'method', + Alternative( + title=_("Forwarding Method"), + elements=[ + Alternative( + title=_("Send events to local event console"), + elements=[ + FixedValue( + "", + totext=_("Directly forward to event console"), + title= + _("Send events to local event console in same OMD site" + ), + ), + TextAscii( + title= + _("Send events to local event console into unix socket" + ), + allow_empty=False, + ), + FixedValue( + "spool:", + totext=_("Spool to event console"), + title= + _("Spooling: Send events to local event console in same OMD site" + ), + ), + Transform( + TextAscii(), + title= + _("Spooling: Send events to local event console into given spool directory" + ), + allow_empty=False, + # remove prefix + forth=lambda x: x[6:], + back=lambda x: "spool:" + x, # add prefix + ), + ], + match= + lambda x: x and (x == 'spool:' and 2 or x.startswith('spool:') and 3 or 1) or 0 + ), + Tuple( + title=_("Send events to remote syslog host"), + elements=[ + DropdownChoice( + choices=[ + ('udp', _('UDP')), + ('tcp', _('TCP')), + ], + title=_("Protocol"), + ), + TextAscii( + title=_("Address"), + allow_empty=False, + ), + Integer( + title=_("Port"), + allow_empty=False, + default_value=514, + minvalue=1, + maxvalue=65535, + size=6, + ), + ]), + ], + )), + ('match_subject', + RegExpUnicode( + title=_('Only process mails with matching subject'), + help= + _('Use this option to not process all messages found in the inbox, ' + 'but only the those whose subject matches the given regular expression.' + ), + mode=RegExp.prefix, + )), + ( + 'facility', + DropdownChoice( + title=_("Events: Syslog facility"), + help=_("Use this syslog facility for all created events"), + choices=mkeventd.syslog_facilities, + default_value=2, # mail + )), + ('application', + Alternative( + title=_("Events: Syslog application"), + help=_("Use this syslog application for all created events"), + elements=[ + FixedValue( + None, + title=_("Use the mail subject"), + totext=_("The mail subject is used as syslog appliaction"), + ), + TextUnicode( + title=_("Specify the application"), + help= + _("Use this text as application. You can use macros like \\1, \\2, ... " + "here when you configured subject matching in this rule with a regular expression " + "that declares match groups (using braces)."), + allow_empty=False, + ), + ])), + ('host', + TextAscii( + title=_('Events: Hostname'), + help= + _('Use this hostname for all created events instead of the name of the mailserver' + ), + )), + ('body_limit', + Integer( + title=_('Limit length of mail body'), + help= + _('When forwarding mails from the mailbox to the event console, the ' + 'body of the mail is limited to the given number of characters.' + ), + default_value=1000, + )), + ('cleanup', + Alternative( + title=_("Cleanup messages"), + help= + _("The handled messages (see subject matching) can be cleaned up by either " + "deleting them or moving them to a subfolder. By default nothing is cleaned up." + ), + elements=[ + FixedValue( + True, + title=_('Delete messages'), + totext=_( + 'Delete all processed message belonging to this check' + ), + ), + TextUnicode( + title=_("Move to subfolder"), + help=_( + "Specify the destination path in the format Path/To/Folder, for example" + "INBOX/Processed_Mails."), + allow_empty=False, + ), + ])), + ])), + ]) + + +@rulespec_registry.register +class RulespecActiveChecksMailboxes(HostRulespec): + @property + def group(self): + return RulespecGroupActiveChecks + + @property + def name(self): + return "active_checks:mailboxes" + + @property + def match_type(self): + return "all" + + @property + def valuespec(self): + return Dictionary( + title=_('Check IMAP Mailboxes'), + help=_('This check monitors count and age of mails in mailboxes.'), + elements=[('service_description', + TextUnicode( + title=_('Service description'), + help=_('Please make sure that this is unique per host ' + 'and does not collide with other services.'), + allow_empty=False, + default_value="Mailboxes")), ('imap_parameters', _imap_parameters()), + ('connect_timeout', + Integer( + title=_('Connect Timeout'), + minvalue=1, + default_value=10, + unit=_('sec'), + )), + ('age', + Tuple( + title=_("Message Age"), + elements=[Age(title=_("Warning at")), + Age(title=_("Critical at"))])), + ('count', + Tuple( + title=_("Message Count"), + elements=[ + Integer(title=_("Warning at")), + Integer(title=_("Critical at")) + ])), + ('mailboxes', + ListOfStrings( + title=_('Check only the listed mailboxes'), + help=_('By default, all mailboxes are checked with these parameters. ' + 'If you specify mailboxes here, only those are monitored.')))], + required_keys=['service_description', 'imap_parameters'], + ) + + +@rulespec_registry.register +class RulespecActiveChecksBySsh(HostRulespec): + @property + def group(self): + return RulespecGroupActiveChecks + + @property + def name(self): + return "active_checks:by_ssh" + + @property + def match_type(self): + return "all" + + @property + def valuespec(self): + return Tuple( + title=_("Check via SSH service"), + help=_("Checks via SSH. "), + elements=[ + TextAscii( + title=_("Command"), + help=_("Command to execute on remote host."), + allow_empty=False, + ), + Dictionary( + title=_("Optional parameters"), + elements=[ + ("description", + TextAscii( + title=_("Service Description"), + help= + _("Must be unique for every host. Defaults to command that is executed." + ), + size=30)), + ("hostname", + TextAscii( + title=_("DNS Hostname or IP address"), + default_value="$HOSTADDRESS$", + allow_empty=False, + help=_( + "You can specify a hostname or IP address different from IP address " + "of the host as configured in your host properties."))), + ('port', + Integer( + title=_("SSH Port"), + help=_("Default is 22."), + minvalue=1, + maxvalue=65535, + default_value=22)), + ("ip_version", + Alternative( + title=_("IP-Version"), + elements=[ + FixedValue("ipv4", totext="", title=_("IPv4")), + FixedValue("ipv6", totext="", title=_("IPv6")), + ], + )), + ("timeout", + Integer( + title=_("Seconds before connection times out"), + unit=_("sec"), + default_value=10, + )), + ("logname", + TextAscii( + title=_("Username"), help=_("SSH user name on remote host"), size=30)), + ("identity", + TextAscii( + title=_("Keyfile"), help=_("Identity of an authorized key"), size=30)), + ]) + ], + ) diff --git a/cmk/gui/plugins/wato/check_parameters/unsorted.py b/cmk/gui/plugins/wato/check_parameters/unsorted.py index 652776c179..42ba2de1a8 100644 --- a/cmk/gui/plugins/wato/check_parameters/unsorted.py +++ b/cmk/gui/plugins/wato/check_parameters/unsorted.py @@ -70,7 +70,7 @@ register_rule( help=_("This rule sets the parameters for the host checks (via check_icmp) " "and also for PING checks on ping-only-hosts. For the host checks only the " "critical state is relevant, the warning levels are ignored."), - elements=check_icmp_params, + elements=check_icmp_params(), ), match="dict") diff --git a/cmk/gui/plugins/wato/inventory.py b/cmk/gui/plugins/wato/inventory.py dissimilarity index 72% index 0468ab27da..d8d406c4cd 100644 --- a/cmk/gui/plugins/wato/inventory.py +++ b/cmk/gui/plugins/wato/inventory.py @@ -1,198 +1,234 @@ -#!/usr/bin/python -# -*- encoding: utf-8; py-indent-offset: 4 -*- -# +------------------------------------------------------------------+ -# | ____ _ _ __ __ _ __ | -# | / ___| |__ ___ ___| | __ | \/ | |/ / | -# | | | | '_ \ / _ \/ __| |/ / | |\/| | ' / | -# | | |___| | | | __/ (__| < | | | | . \ | -# | \____|_| |_|\___|\___|_|\_\___|_| |_|_|\_\ | -# | | -# | Copyright Mathias Kettner 2014 mk@mathias-kettner.de | -# +------------------------------------------------------------------+ -# -# This file is part of Check_MK. -# The official homepage is at http://mathias-kettner.de/check_mk. -# -# check_mk is free software; you can redistribute it and/or modify it -# under the terms of the GNU General Public License as published by -# the Free Software Foundation in version 2. check_mk is distributed -# in the hope that it will be useful, but WITHOUT ANY WARRANTY; with- -# out even the implied warranty of MERCHANTABILITY or FITNESS FOR A -# PARTICULAR PURPOSE. See the GNU General Public License for more de- -# tails. You should have received a copy of the GNU General Public -# License along with GNU Make; see the file COPYING. If not, write -# to the Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, -# Boston, MA 02110-1301 USA. - -import cmk.utils.paths -import cmk.utils.defines as defines - -from cmk.gui.valuespec import ( - DualListChoice, - Age, - Dictionary, - Transform, - DropdownChoice, - TextAscii, - MonitoringState, -) -from cmk.gui.i18n import _ - -from cmk.gui.plugins.wato import ( - rulespec_group_registry, - RulespecGroup, - register_rule, -) - - -@rulespec_group_registry.register -class RulespecGroupInventory(RulespecGroup): - @property - def name(self): - return "inventory" - - @property - def title(self): - return _("Hardware / Software Inventory") - - @property - def help(self): - return _("Configuration of the Check_MK Hardware and Software Inventory System") - - -register_rule( - RulespecGroupInventory, - "active_checks:cmk_inv", - Transform( - Dictionary(elements=[ - ("sw_changes", - MonitoringState( - title=_("State when software changes are detected"), - default_value=0, - )), - ("sw_missing", - MonitoringState( - title=_("State when software packages info is missing"), - default_value=0, - )), - ("hw_changes", - MonitoringState( - title=_("State when hardware changes are detected"), - default_value=0, - )), - ("fail_status", - MonitoringState( - title=_("State when inventory fails"), - help=_("The check takes this state in case the inventory cannot be " - "updated because of any possible reason. A common use is " - "setting this to OK for workstations that can be switched " - "off - so you will get no notifications in that case."), - default_value=1, - )), - ("status_data_inventory", - DropdownChoice( - title=_("Status data inventory"), - help=_("All hosts configured via this ruleset will do a hardware and " - "software inventory after every check cycle if there's at least " - "one inventory plugin which processes status data. " - "Note: in order to get any useful " - "result for agent based hosts make sure that you have installed " - "the agent plugin mk_inventory on these hosts."), - choices=[ - (True, _("Do status data inventory")), - (False, _("Do not status data inventory")), - ], - default_value=True, - )), - ]), - title=_("Do hardware/software Inventory"), - help=_("All hosts configured via this ruleset will do a hardware and " - "software inventory. For each configured host a new active check " - "will be created. You should also create a rule for changing the " - "normal interval for that check to something between a couple of " - "hours and one day. " - "Note: in order to get any useful " - "result for agent based hosts make sure that you have installed " - "the agent plugin mk_inventory on these hosts."), - forth=lambda x: x is not None and x or {}, # convert from legacy None - ), - match="all", -) - -register_rule( - RulespecGroupInventory, - "inv_exports:software_csv", - Dictionary( - title=_("Export List of Software packages as CSV file"), - elements=[ - ("filename", - TextAscii( - title=_( - "Export file to create, containing &ly;HOST> for the hostname"), - help=_( - "Please specify the path to the export file. The text <HOST> " - "will be replaced with the host name the inventory has been done for. " - "If you use a relative path then that will be relative to Check_MK's directory " - "for variable data, which is %s.") % cmk.utils.paths.var_dir, - allow_empty=False, - size=64, - default_value="csv-export/.csv", - )), - ("separator", - TextAscii( - title=_("Separator"), - allow_empty=False, - size=1, - default_value=";", - )), - ("quotes", - DropdownChoice( - title=_("Quoting"), - choices=[ - (None, _("Don't use quotes")), - ("single", _("Use single quotes, escape contained quotes with backslash")), - ("double", _("Use double quotes, escape contained quotes with backslash")), - ], - default_value=None, - )), - ("headers", - DropdownChoice( - title=_("Column headers"), - choices=[ - (False, _("Do not add column headers")), - (True, _("Add a first row with column titles")), - ], - default_value=False, - )), - ], - required_keys=["filename"], - ), - match="first") - -register_rule( - RulespecGroupInventory, - "inv_parameters:inv_if", - Dictionary( - title=_("Parameters for switch port inventory"), - elements=[ - ("unused_duration", - Age( - title=_("Port down time until considered unused"), - help=_("After this time in the state down a port is considered unused."), - default_value=30 * 86400, - )), - ("usage_port_types", - DualListChoice( - title=_("Port types to include in usage statistics"), - choices=defines.interface_port_types(), - autoheight=False, - rows=40, - enlarge_active=False, - custom_order=True, - default_value=[ - '6', '32', '62', '117', '127', '128', '129', '180', '181', '182', '205', '229' - ], - )), - ]), - match="dict", -) +#!/usr/bin/python +# -*- encoding: utf-8; py-indent-offset: 4 -*- +# +------------------------------------------------------------------+ +# | ____ _ _ __ __ _ __ | +# | / ___| |__ ___ ___| | __ | \/ | |/ / | +# | | | | '_ \ / _ \/ __| |/ / | |\/| | ' / | +# | | |___| | | | __/ (__| < | | | | . \ | +# | \____|_| |_|\___|\___|_|\_\___|_| |_|_|\_\ | +# | | +# | Copyright Mathias Kettner 2014 mk@mathias-kettner.de | +# +------------------------------------------------------------------+ +# +# This file is part of Check_MK. +# The official homepage is at http://mathias-kettner.de/check_mk. +# +# check_mk is free software; you can redistribute it and/or modify it +# under the terms of the GNU General Public License as published by +# the Free Software Foundation in version 2. check_mk is distributed +# in the hope that it will be useful, but WITHOUT ANY WARRANTY; with- +# out even the implied warranty of MERCHANTABILITY or FITNESS FOR A +# PARTICULAR PURPOSE. See the GNU General Public License for more de- +# tails. You should have received a copy of the GNU General Public +# License along with GNU Make; see the file COPYING. If not, write +# to the Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, +# Boston, MA 02110-1301 USA. + +import cmk.utils.paths +import cmk.utils.defines as defines + +from cmk.gui.valuespec import ( + DualListChoice, + Age, + Dictionary, + Transform, + DropdownChoice, + TextAscii, + MonitoringState, +) +from cmk.gui.i18n import _ + +from cmk.gui.plugins.wato import ( + rulespec_group_registry, + RulespecGroup, + rulespec_registry, + HostRulespec, +) + + +@rulespec_group_registry.register +class RulespecGroupInventory(RulespecGroup): + @property + def name(self): + return "inventory" + + @property + def title(self): + return _("Hardware / Software Inventory") + + @property + def help(self): + return _("Configuration of the Check_MK Hardware and Software Inventory System") + + +@rulespec_registry.register +class RulespecActiveChecksCmkInv(HostRulespec): + @property + def group(self): + return RulespecGroupInventory + + @property + def name(self): + return "active_checks:cmk_inv" + + @property + def match_type(self): + return "all" + + @property + def valuespec(self): + return Transform( + Dictionary(elements=[ + ("sw_changes", + MonitoringState( + title=_("State when software changes are detected"), + default_value=0, + )), + ("sw_missing", + MonitoringState( + title=_("State when software packages info is missing"), + default_value=0, + )), + ("hw_changes", + MonitoringState( + title=_("State when hardware changes are detected"), + default_value=0, + )), + ("fail_status", + MonitoringState( + title=_("State when inventory fails"), + help=_("The check takes this state in case the inventory cannot be " + "updated because of any possible reason. A common use is " + "setting this to OK for workstations that can be switched " + "off - so you will get no notifications in that case."), + default_value=1, + )), + ("status_data_inventory", + DropdownChoice( + title=_("Status data inventory"), + help=_("All hosts configured via this ruleset will do a hardware and " + "software inventory after every check cycle if there's at least " + "one inventory plugin which processes status data. " + "Note: in order to get any useful " + "result for agent based hosts make sure that you have installed " + "the agent plugin mk_inventory on these hosts."), + choices=[ + (True, _("Do status data inventory")), + (False, _("Do not status data inventory")), + ], + default_value=True, + )), + ]), + title=_("Do hardware/software Inventory"), + help=_("All hosts configured via this ruleset will do a hardware and " + "software inventory. For each configured host a new active check " + "will be created. You should also create a rule for changing the " + "normal interval for that check to something between a couple of " + "hours and one day. " + "Note: in order to get any useful " + "result for agent based hosts make sure that you have installed " + "the agent plugin mk_inventory on these hosts."), + forth=lambda x: x is not None and x or {}, # convert from legacy None + ) + + +@rulespec_registry.register +class RulespecInvExportsSoftwareCsv(HostRulespec): + @property + def group(self): + return RulespecGroupInventory + + @property + def name(self): + return "inv_exports:software_csv" + + @property + def valuespec(self): + return Dictionary( + title=_("Export List of Software packages as CSV file"), + elements=[ + ("filename", + TextAscii( + title=_( + "Export file to create, containing &ly;HOST> for the hostname" + ), + help= + _("Please specify the path to the export file. The text <HOST> " + "will be replaced with the host name the inventory has been done for. " + "If you use a relative path then that will be relative to Check_MK's directory " + "for variable data, which is %s.") % cmk.utils.paths.var_dir, + allow_empty=False, + size=64, + default_value="csv-export/.csv", + )), + ("separator", + TextAscii( + title=_("Separator"), + allow_empty=False, + size=1, + default_value=";", + )), + ("quotes", + DropdownChoice( + title=_("Quoting"), + choices=[ + (None, _("Don't use quotes")), + ("single", _("Use single quotes, escape contained quotes with backslash")), + ("double", _("Use double quotes, escape contained quotes with backslash")), + ], + default_value=None, + )), + ("headers", + DropdownChoice( + title=_("Column headers"), + choices=[ + (False, _("Do not add column headers")), + (True, _("Add a first row with column titles")), + ], + default_value=False, + )), + ], + required_keys=["filename"], + ) + + +@rulespec_registry.register +class RulespecInvParametersInvIf(HostRulespec): + @property + def group(self): + return RulespecGroupInventory + + @property + def name(self): + return "inv_parameters:inv_if" + + @property + def match_type(self): + return "dict" + + @property + def valuespec(self): + return Dictionary( + title=_("Parameters for switch port inventory"), + elements=[ + ("unused_duration", + Age( + title=_("Port down time until considered unused"), + help=_( + "After this time in the state down a port is considered unused."), + default_value=30 * 86400, + )), + ("usage_port_types", + DualListChoice( + title=_("Port types to include in usage statistics"), + choices=defines.interface_port_types(), + autoheight=False, + rows=40, + enlarge_active=False, + custom_order=True, + default_value=[ + '6', '32', '62', '117', '127', '128', '129', '180', '181', '182', '205', + '229' + ], + )), + ]) diff --git a/cmk/gui/wato/mkeventd.py b/cmk/gui/wato/mkeventd.py index 67f0393958..1377387588 100644 --- a/cmk/gui/wato/mkeventd.py +++ b/cmk/gui/wato/mkeventd.py @@ -121,7 +121,9 @@ from cmk.gui.plugins.wato.utils import ( make_action_link, rulespec_group_registry, RulespecGroup, - register_rule, + rulespec_registry, + HostRulespec, + ServiceRulespec, main_module_registry, MainModule, wato_confirm, @@ -3738,129 +3740,152 @@ def convert_mkevents_hostspec(value): return value -register_rule( - RulespecGroupEventConsole, - "extra_host_conf:_ec_event_limit", - Transform( - vs_ec_host_limit(title=_("Host event limit")), - forth=lambda x: dict([("limit", int(x.split(":")[0])), ("action", x.split(":")[1])]), - back=lambda x: "%d:%s" % (x["limit"], x["action"]), - ), - match="first", -) +@rulespec_registry.register +class RulespecExtraHostConfEcEventLimit(HostRulespec): + @property + def group(self): + return RulespecGroupEventConsole -register_rule( - RulespecGroupEventConsole, - "active_checks:mkevents", - Dictionary( - title=_("Check event state in Event Console"), - help=_("This check is part of the Check_MK Event Console and will check " - "if there are any open events for a certain host (and maybe a certain " - "application on that host. The state of the check will reflect the status " - "of the worst open event for that host."), - elements=[ - ("hostspec", - Transform( - Alternative( - title=_("Host specification"), - elements=[ - ListChoice( - title=_("Match the hosts with..."), - choices=[ - ('$HOSTNAME$', _("Hostname")), - ('$HOSTADDRESS$', _("IP address")), - ('$HOSTALIAS$', _("Alias")), - ]), - TextAscii( - allow_empty=False, attrencode=True, title="Specify host explicitely"), - ], - default_value=['$HOSTNAME$', '$HOSTADDRESS$']), - help=_( - "When quering the event status you can either use the monitoring " - "host name, the IP address, the host alias or a custom host name for referring to a " - "host. This is needed in cases where the event source (syslog, snmptrapd) " - "do not send a host name that matches the monitoring host name."), - forth=convert_mkevents_hostspec)), - ("item", - TextAscii( - title=_("Item (used in service description)"), - help=_("If you enter an item name here, this will be used as " - "part of the service description after the prefix \"Events \". " - "The prefix plus the configured item must result in an unique " - "service description per host. If you leave this empty either the " - "string provided in \"Application\" is used as item or the service " - "gets no item when the \"Application\" field is also not configured."), - allow_empty=False, - )), - ("application", - RegExp( - title=_("Application (regular expression)"), - help=_("If you enter an application name here then only " - "events for that application name are counted. You enter " - "a regular expression here that must match a part " - "of the application name. Use anchors ^ and $ " - "if you need a complete match."), - allow_empty=False, - mode=RegExp.infix, - case_sensitive=False, - )), - ("ignore_acknowledged", - FixedValue( - True, - title=_("Ignore acknowledged events"), - help=_("If you check this box then only open events are honored when " - "determining the event state. Acknowledged events are displayed " - "(i.e. their count) but not taken into account."), - totext=_("acknowledged events will not be honored"), - )), - ("remote", - Alternative( - title=_("Access to the Event Console"), - style="dropdown", - elements=[ - FixedValue( - None, - title=_("Connect to the local Event Console"), - totext=_("local connect"), - ), - Tuple( + @property + def name(self): + return "extra_host_conf:_ec_event_limit" + + @property + def valuespec(self): + return Transform( + vs_ec_host_limit(title=_("Host event limit")), + forth=lambda x: dict([("limit", int(x.split(":")[0])), ("action", x.split(":")[1])]), + back=lambda x: "%d:%s" % (x["limit"], x["action"]), + ) + + +@rulespec_registry.register +class RulespecActiveChecksMkevents(HostRulespec): + @property + def group(self): + return RulespecGroupEventConsole + + @property + def name(self): + return "active_checks:mkevents" + + @property + def match_type(self): + return "all" + + @property + def valuespec(self): + return Dictionary( + title=_("Check event state in Event Console"), + help=_("This check is part of the Check_MK Event Console and will check " + "if there are any open events for a certain host (and maybe a certain " + "application on that host. The state of the check will reflect the status " + "of the worst open event for that host."), + elements=[ + ("hostspec", + Transform( + Alternative( + title=_("Host specification"), elements=[ + ListChoice( + title=_("Match the hosts with..."), + choices=[ + ('$HOSTNAME$', _("Hostname")), + ('$HOSTADDRESS$', _("IP address")), + ('$HOSTALIAS$', _("Alias")), + ]), TextAscii( - title=_("Hostname/IP address of Event Console:"), allow_empty=False, attrencode=True, - ), - Integer( - title=_("TCP Port number:"), - minvalue=1, - maxvalue=65535, - default_value=6558, - ), + title="Specify host explicitely"), ], - title=_("Access via TCP"), - help= - _("In a distributed setup where the Event Console is not running in the same " - "site as the host is monitored you need to access the remote Event Console " - "via TCP. Please make sure that this is activated in the global settings of " - "the event console. The default port number is 6558."), - ), - TextAscii( - title=_("Access via UNIX socket"), - allow_empty=False, - size=64, - attrencode=True, - ), - ], - default_value=None, - )), - ], - optional_keys=["application", "remote", "ignore_acknowledged", "item"], - ignored_keys=["less_verbose"], # is deprecated - ), - match='all', -) + default_value=['$HOSTNAME$', '$HOSTADDRESS$']), + help=_( + "When quering the event status you can either use the monitoring " + "host name, the IP address, the host alias or a custom host name for referring to a " + "host. This is needed in cases where the event source (syslog, snmptrapd) " + "do not send a host name that matches the monitoring host name."), + forth=convert_mkevents_hostspec)), + ("item", + TextAscii( + title=_("Item (used in service description)"), + help=_("If you enter an item name here, this will be used as " + "part of the service description after the prefix \"Events \". " + "The prefix plus the configured item must result in an unique " + "service description per host. If you leave this empty either the " + "string provided in \"Application\" is used as item or the service " + "gets no item when the \"Application\" field is also not configured."), + allow_empty=False, + )), + ("application", + RegExp( + title=_("Application (regular expression)"), + help=_("If you enter an application name here then only " + "events for that application name are counted. You enter " + "a regular expression here that must match a part " + "of the application name. Use anchors ^ and $ " + "if you need a complete match."), + allow_empty=False, + mode=RegExp.infix, + case_sensitive=False, + )), + ("ignore_acknowledged", + FixedValue( + True, + title=_("Ignore acknowledged events"), + help=_("If you check this box then only open events are honored when " + "determining the event state. Acknowledged events are displayed " + "(i.e. their count) but not taken into account."), + totext=_("acknowledged events will not be honored"), + )), + ("remote", + Alternative( + title=_("Access to the Event Console"), + style="dropdown", + elements=[ + FixedValue( + None, + title=_("Connect to the local Event Console"), + totext=_("local connect"), + ), + Tuple( + elements=[ + TextAscii( + title=_("Hostname/IP address of Event Console:"), + allow_empty=False, + attrencode=True, + ), + Integer( + title=_("TCP Port number:"), + minvalue=1, + maxvalue=65535, + default_value=6558, + ), + ], + title=_("Access via TCP"), + help= + _("In a distributed setup where the Event Console is not running in the same " + "site as the host is monitored you need to access the remote Event Console " + "via TCP. Please make sure that this is activated in the global settings of " + "the event console. The default port number is 6558."), + ), + TextAscii( + title=_("Access via UNIX socket"), + allow_empty=False, + size=64, + attrencode=True, + ), + ], + default_value=None, + )), + ], + optional_keys=["application", "remote", "ignore_acknowledged", "item"], + ignored_keys=["less_verbose"], # is deprecated + ) -sl_help = _("A service level is a number that describes the business impact of a host or " + +def _sl_help(): + return _("A service level is a number that describes the business impact of a host or " "service. This level can be used in rules for notifications, as a filter in " "views or as a criteria in rules for the Event Console. A higher service level " "is assumed to be more business critical. This ruleset allows to assign service " @@ -3872,67 +3897,97 @@ sl_help = _("A service level is a number that describes the business impact of a "levels is configured via a global option.") % \ "wato.py?varname=mkeventd_service_levels&mode=edit_configvar" -register_rule( - RulespecGroupGrouping, - "extra_host_conf:_ec_sl", - DropdownChoice( - title=_("Service Level of hosts"), - help=sl_help, - choices=cmk.gui.mkeventd.service_levels, - ), - match='first', -) -register_rule( - RulespecGroupGrouping, - "extra_service_conf:_ec_sl", - DropdownChoice( - title=_("Service Level of services"), - help=sl_help + _(" Note: if no service level is configured for a service " - "then that of the host will be used instead (if configured)."), - choices=cmk.gui.mkeventd.service_levels, - ), - itemtype='service', - match='first', -) +@rulespec_registry.register +class RulespecExtraHostConfEcSl(HostRulespec): + @property + def group(self): + return RulespecGroupGrouping -contact_help = _("This rule set is useful if you send your monitoring notifications " - "into the Event Console. The contact information that is set by this rule " - "will be put into the resulting event in the Event Console.") -contact_regex = r"^[^;'$|]*$" -contact_regex_error = _( - "The contact information must not contain one of the characters ; ' | or $" -) + @property + def name(self): + return "extra_host_conf:_ec_sl" -register_rule( - RulespecGroupEventConsole, - "extra_host_conf:_ec_contact", - TextUnicode( - title=_("Host contact information"), - help=contact_help, - size=80, - regex=contact_regex, - regex_error=contact_regex_error, - attrencode=True, - ), - match='first', -) + @property + def valuespec(self): + return DropdownChoice( + title=_("Service Level of hosts"), + help=_sl_help(), + choices=cmk.gui.mkeventd.service_levels, + ) + + +@rulespec_registry.register +class RulespecExtraServiceConfEcSl(ServiceRulespec): + @property + def group(self): + return RulespecGroupGrouping + + @property + def name(self): + return "extra_service_conf:_ec_sl" + + @property + def item_type(self): + return "service" + + @property + def valuespec(self): + return DropdownChoice( + title=_("Service Level of services"), + help=_sl_help() + _(" Note: if no service level is configured for a service " + "then that of the host will be used instead (if configured)."), + choices=cmk.gui.mkeventd.service_levels, + ) -register_rule( - RulespecGroupEventConsole, - "extra_service_conf:_ec_contact", - TextUnicode( - title=_("Service contact information"), - help=contact_help + _(" Note: if no contact information is configured for a service " - "then that of the host will be used instead (if configured)."), + +def _vs_contact(title): + return TextUnicode( + title=title, + help=_("This rule set is useful if you send your monitoring notifications " + "into the Event Console. The contact information that is set by this rule " + "will be put into the resulting event in the Event Console.") + _( + " Note: if no contact information is configured for a service " + "then that of the host will be used instead (if configured)."), size=80, - regex=contact_regex, - regex_error=contact_regex_error, - attrencode=True, - ), - itemtype='service', - match='first', -) + regex=r"^[^;'$|]*$", + regex_error=_("The contact information must not contain one of the characters " + "; ' | or $"), + ) + + +@rulespec_registry.register +class RulespecExtraHostConfEcContact(HostRulespec): + @property + def group(self): + return RulespecGroupEventConsole + + @property + def name(self): + return "extra_host_conf:_ec_contact" + + @property + def valuespec(self): + return _vs_contact(_("Host contact information")) + + +@rulespec_registry.register +class RulespecExtraServiceConfEcContact(ServiceRulespec): + @property + def group(self): + return RulespecGroupEventConsole + + @property + def name(self): + return "extra_service_conf:_ec_contact" + + @property + def item_type(self): + return "service" + + @property + def valuespec(self): + return _vs_contact(title=_("Service contact information")) #. diff --git a/tests/unit/cmk/gui/watolib/test_rulespecs.py b/tests/unit/cmk/gui/watolib/test_rulespecs.py index e5302ea1cc..ae2223ece9 100644 --- a/tests/unit/cmk/gui/watolib/test_rulespecs.py +++ b/tests/unit/cmk/gui/watolib/test_rulespecs.py @@ -9421,7 +9421,7 @@ expected_rulespecs = { 'extra_host_conf:_ec_contact': { 'factory_default': [], 'group_name': 'eventconsole', - 'help': u'This rule set is useful if you send your monitoring notifications into the Event Console. The contact information that is set by this rule will be put into the resulting event in the Event Console.', + 'help': u'This rule set is useful if you send your monitoring notifications into the Event Console. The contact information that is set by this rule will be put into the resulting event in the Event Console. Note: if no contact information is configured for a service then that of the host will be used instead (if configured).', 'is_deprecated': False, 'is_optional': False, 'item_enum': None, -- 2.11.4.GIT