Module: check_mk
Branch: master
Commit: 5405469a2a78c867b810868a7460a4009d219975
URL: http://git.mathias-kettner.de/git/?p=check_mk.git;a=commit;h=5405469a2a78c8…
Author: Mathias Kettner <mk(a)mathias-kettner.de>
Date: Fri Sep 16 13:51:14 2016 +0200
Code cleanup: prefix non-public functions with _ in sites.py
---
web/htdocs/sites.py | 119 ++++++++++++++++++++++++++++++++--------------------
1 file changed, 74 insertions(+), 45 deletions(-)
diff --git a/web/htdocs/sites.py b/web/htdocs/sites.py
index 9537de1..9381ca0 100644
--- a/web/htdocs/sites.py
+++ b/web/htdocs/sites.py
@@ -28,53 +28,88 @@ import config
import defaults
import livestatus
-# The global livestatus object. This is initialized automatically upon first access
-# to the accessor function live()
-_live = None
-
-# _site_status keeps a dictionary for each site with the following keys:
-# "state" --> "online", "disabled", "down", "unreach", "dead" or "waiting"
-# "exception" --> An error exception in case of down, unreach, dead or waiting
-# "status_host_state" --> host state of status host (0, 1, 2 or None)
-# "livestatus_version" --> Version of sites livestatus if "online"
-# "program_version" --> Version of Nagios if "online"
-_site_status = None
+# .--API-----------------------------------------------------------------.
+# | _ ____ ___ |
+# | / \ | _ \_ _| |
+# | / _ \ | |_) | | |
+# | / ___ \| __/| | |
+# | /_/ \_\_| |___| |
+# | |
+# +----------------------------------------------------------------------+
+# | Functions und names for the public |
+# '----------------------------------------------------------------------'
-# Accessor and initializer to the global livestatus connection object
def live():
+ """Get Livestatus connection object matching the current site configuration
+ and user settings. On the first call the actual connection is being made."""
if _live == None:
- connect()
+ _connect()
return _live
# Accessor for the status of a single site
def state(site_id, deflt=None):
+ """Get the status of a certain site. Returns a dictionary with various
+ entries. deflt is being returned in case the specified site doe not
+ exist or has no state."""
if _live == None:
- connect()
+ _connect()
return _site_status.get(site_id, deflt)
-# Returns dictionary of all known site states
def states():
+ """Returns dictionary of all known site states."""
if _live == None:
- connect()
+ _connect()
return _site_status
-# Build up a connection to livestatus to either a single site or multiple sites.
-def connect():
- init_site_status()
- connect_multiple_sites()
- set_livestatus_auth()
+def disconnect():
+ """Actively closes all Livestatus connections."""
+ global _live, _site_status
+ _live = None
+ _site_status = None
+
-def connect_multiple_sites():
- global _live
- enabled_sites, disabled_sites = get_enabled_and_disabled_sites()
- set_initial_site_states(enabled_sites, disabled_sites)
+#.
+# .--Internal------------------------------------------------------------.
+# | ___ _ _ |
+# | |_ _|_ __ | |_ ___ _ __ _ __ __ _| | |
+# | | || '_ \| __/ _ \ '__| '_ \ / _` | | |
+# | | || | | | || __/ | | | | | (_| | | |
+# | |___|_| |_|\__\___|_| |_| |_|\__,_|_| |
+# | |
+# +----------------------------------------------------------------------+
+# | Internal functiions and variables |
+# '----------------------------------------------------------------------'
+# The global livestatus object. This is initialized automatically upon first access
+# to the accessor function live()
+_live = None
+
+# _site_status keeps a dictionary for each site with the following keys:
+# "state" --> "online", "disabled", "down", "unreach", "dead" or "waiting"
+# "exception" --> An error exception in case of down, unreach, dead or waiting
+# "status_host_state" --> host state of status host (0, 1, 2 or None)
+# "livestatus_version" --> Version of sites livestatus if "online"
+# "program_version" --> Version of Nagios if "online"
+_site_status = None
+
+
+# Build up a connection to livestatus to either a single site or multiple sites.
+def _connect():
+ _init_site_status()
+ _connect_multiple_sites()
+ _set_livestatus_auth()
+
+
+def _connect_multiple_sites():
+ global _live
+ enabled_sites, disabled_sites = _get_enabled_and_disabled_sites()
+ _set_initial_site_states(enabled_sites, disabled_sites)
_live = livestatus.MultiSiteConnection(enabled_sites, disabled_sites)
# Fetch status of sites by querying the version of Nagios and livestatus
@@ -84,7 +119,7 @@ def connect_multiple_sites():
"GET status\n"
"Cache: reload\n"
"Columns: livestatus_version program_version program_start num_hosts num_services"):
- update_site_status(site_id, {
+ _update_site_status(site_id, {
"state" : "online",
"livestatus_version" : v1,
"program_version" : v2,
@@ -98,14 +133,14 @@ def connect_multiple_sites():
# Get exceptions in case of dead sites
for site_id, deadinfo in _live.dead_sites().items():
shs = deadinfo.get("status_host_state")
- update_site_status(site_id, {
+ _update_site_status(site_id, {
"exception" : deadinfo["exception"],
"status_host_state" : shs,
- "state" : status_host_state_name(shs),
+ "state" : _status_host_state_name(shs),
})
-def get_enabled_and_disabled_sites():
+def _get_enabled_and_disabled_sites():
enabled_sites, disabled_sites = {}, {}
for site_id, site in config.allsites().items():
@@ -129,8 +164,8 @@ def get_enabled_and_disabled_sites():
# If Multisite is retricted to data the user is a contact for, we need to set an
# AuthUser: header for livestatus.
-def set_livestatus_auth():
- user_id = livestatus_auth_user()
+def _set_livestatus_auth():
+ user_id = _livestatus_auth_user()
if user_id != None:
_live.set_auth_user('read', user_id)
_live.set_auth_user('action', user_id)
@@ -149,7 +184,7 @@ def set_livestatus_auth():
# Returns either None when no auth user shal be set or the name of the user
# to be used as livestatus auth user
-def livestatus_auth_user():
+def _livestatus_auth_user():
if not config.may("general.see_all"):
return config.user_id
@@ -171,41 +206,35 @@ def livestatus_auth_user():
return None
-def disconnect():
- global _live, _site_status
- _live = None
- _site_status = None
-
-
-def status_host_state_name(shs):
+def _status_host_state_name(shs):
if shs == None:
return "dead"
else:
return { 1:"down", 2:"unreach", 3:"waiting", }.get(shs, "unknown")
-def init_site_status():
+def _init_site_status():
global _site_status
_site_status = {}
-def set_initial_site_states(enabled_sites, disabled_sites):
+def _set_initial_site_states(enabled_sites, disabled_sites):
for site_id, site in enabled_sites.items():
- set_site_status(site_id, {
+ _set_site_status(site_id, {
"state" : "dead",
"site" : site
})
for site_id, site in disabled_sites.items():
- set_site_status(site_id, {
+ _set_site_status(site_id, {
"state" : "disabled",
"site" : site
})
-def set_site_status(site_id, status):
+def _set_site_status(site_id, status):
_site_status[site_id] = status
-def update_site_status(site_id, status):
+def _update_site_status(site_id, status):
_site_status[site_id].update(status)
Module: check_mk
Branch: master
Commit: 7ad8f78f1040915e63b433b3e616b10943c9295e
URL: http://git.mathias-kettner.de/git/?p=check_mk.git;a=commit;h=7ad8f78f104091…
Author: Andreas Boesl <ab(a)mathias-kettner.de>
Date: Fri Sep 16 13:45:54 2016 +0200
3805 WATO WebAPI: The configuration of cluster nodes is now officially supported
You can now set the new key <tt>nodes</tt> in the add_host and edit_host operations.
The value is a list of cluster node names. A host is treated as normal host if the key
is entirely missing or if the node list is empty.
---
.werks/3805 | 12 ++++++++++++
ChangeLog | 1 +
web/plugins/webapi/webapi.py | 23 +++++++++++------------
3 files changed, 24 insertions(+), 12 deletions(-)
diff --git a/.werks/3805 b/.werks/3805
new file mode 100644
index 0000000..10c0344
--- /dev/null
+++ b/.werks/3805
@@ -0,0 +1,12 @@
+Title: WATO WebAPI: The configuration of cluster nodes is now officially supported
+Level: 1
+Component: wato
+Compatible: compat
+Version: 1.4.0i1
+Date: 1474026075
+Class: feature
+
+You can now set the new key <tt>nodes</tt> in the add_host and edit_host operations.
+The value is a list of cluster node names. A host is treated as normal host if the key
+is entirely missing or if the node list is empty.
+
diff --git a/ChangeLog b/ChangeLog
index da65413..4fb009b 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -528,6 +528,7 @@
* 3851 Host edit dialog: Checkbox hosttags are now checked by default...
* 3800 WATO rule overview: Adjusted wording of condition texts
* 3855 SEC: Fixed possible command injection by privileged WATO users...
+ * 3805 WATO WebAPI: The configuration of cluster nodes is now officially supported...
* 3060 FIX: Folder properties: Fixed exception when a user has no alias set...
* 3062 FIX: Git integration: Fixed not adding files in WATO folders to git control
* 3203 FIX: Distributed WATO: Fixed exception in remote host service discovery...
diff --git a/web/plugins/webapi/webapi.py b/web/plugins/webapi/webapi.py
index a3de28c..2b4488a 100644
--- a/web/plugins/webapi/webapi.py
+++ b/web/plugins/webapi/webapi.py
@@ -76,16 +76,17 @@ def validate_host_attributes(attributes):
def action_add_host(request):
- validate_request_keys(request, ["hostname", "folder", "attributes"])
+ validate_request_keys(request, ["hostname", "folder", "attributes", "nodes"])
if html.var("create_folders"):
create_folders = bool(int(html.var("create_folders")))
else:
create_folders = True
- hostname = request.get("hostname")
- folder_path = request.get("folder")
- attributes = request.get("attributes", {})
+ hostname = request.get("hostname")
+ folder_path = request.get("folder")
+ attributes = request.get("attributes", {})
+ cluster_nodes = request.get("nodes")
# Validate hostname
if not hostname:
@@ -106,9 +107,8 @@ def action_add_host(request):
folder_path = ""
folders = [""]
- # Validate and cleanup given attributes
- # CLEANUP: modify WebAPI .nodes argument
- cluster_nodes = None
+ # Deprecated, but still supported
+ # Nodes are now specified in an extra key
if ".nodes" in attributes:
cluster_nodes = attributes[".nodes"]
del attributes[".nodes"]
@@ -131,11 +131,12 @@ api_actions["add_host"] = {
###############
def action_edit_host(request):
- validate_request_keys(request, ["hostname", "unset_attributes", "attributes"])
+ validate_request_keys(request, ["hostname", "unset_attributes", "attributes", "nodes"])
hostname = request.get("hostname")
attributes = request.get("attributes", {})
unset_attribute_names = request.get("unset_attributes", [])
+ cluster_nodes = request.get("nodes")
# Validate host
if not hostname:
@@ -145,10 +146,8 @@ def action_edit_host(request):
if not host:
raise MKUserError(None, _("No such host"))
- # Only validate the new attributes
- attributes = request.get("attributes", {})
- # CLEANUP: modify WebAPI .nodes argument
- cluster_nodes = None
+ # Deprecated, but still supported
+ # Nodes are now specified in an extra key
if ".nodes" in attributes:
cluster_nodes = attributes[".nodes"]
del attributes[".nodes"]
Module: check_mk
Branch: master
Commit: 1c4e79aa45d55bdab24b6f54bb35ec261aefff50
URL: http://git.mathias-kettner.de/git/?p=check_mk.git;a=commit;h=1c4e79aa45d55b…
Author: Mathias Kettner <mk(a)mathias-kettner.de>
Date: Fri Sep 16 13:12:54 2016 +0200
Removed unused code from sites.py module
---
web/htdocs/sites.py | 33 ++-------------------------------
1 file changed, 2 insertions(+), 31 deletions(-)
diff --git a/web/htdocs/sites.py b/web/htdocs/sites.py
index fae3964..9537de1 100644
--- a/web/htdocs/sites.py
+++ b/web/htdocs/sites.py
@@ -32,7 +32,7 @@ import livestatus
# to the accessor function live()
_live = None
-# site_status keeps a dictionary for each site with the following keys:
+# _site_status keeps a dictionary for each site with the following keys:
# "state" --> "online", "disabled", "down", "unreach", "dead" or "waiting"
# "exception" --> An error exception in case of down, unreach, dead or waiting
# "status_host_state" --> host state of status host (0, 1, 2 or None)
@@ -65,13 +65,7 @@ def states():
# Build up a connection to livestatus to either a single site or multiple sites.
def connect():
init_site_status()
-
- # If there is only one site (non-multisite), then user cannot enable/disable.
- if config.is_multisite():
- connect_multiple_sites()
- else:
- connect_single_site()
-
+ connect_multiple_sites()
set_livestatus_auth()
@@ -132,21 +126,6 @@ def get_enabled_and_disabled_sites():
return enabled_sites, disabled_sites
-def connect_single_site():
- global _live
- _live = livestatus.SingleSiteConnection("unix:" + defaults.livestatus_unix_socket)
- _live.set_timeout(3) # default timeout is 3 seconds
-
- set_initial_site_states({"": config.site("")}, {})
-
- v1, v2, ps = _live.query_row("GET status\nColumns: livestatus_version program_version program_start")
- update_local_site_status({
- "state" : "online",
- "livestatus_version" : v1,
- "program_version" : v2,
- "program_start" : ps,
- })
-
# If Multisite is retricted to data the user is a contact for, we need to set an
# AuthUser: header for livestatus.
@@ -224,17 +203,9 @@ def set_initial_site_states(enabled_sites, disabled_sites):
})
-def set_local_site_status(status):
- set_site_status("", status)
-
-
def set_site_status(site_id, status):
_site_status[site_id] = status
-def update_local_site_status(status):
- update_site_status("", status)
-
-
def update_site_status(site_id, status):
_site_status[site_id].update(status)
Module: check_mk
Branch: master
Commit: 25b01e1c7a734b21698d1fb71a6368e5f35fe275
URL: http://git.mathias-kettner.de/git/?p=check_mk.git;a=commit;h=25b01e1c7a734b…
Author: Lars Michelsen <lm(a)mathias-kettner.de>
Date: Fri Sep 16 09:15:35 2016 +0200
3859 check_mail_loop.vbs: New MRPE script to perform a mail loop check via Outlook MAPI
The check is similar to the default check_mail_loop active check (which can be configured
via WATO), but it works using Outlook and the MAPI protocol to send and receive mails. So
you can construct a mail loop checking your Exchange mail infrastrucure without involving
other protocols like IMAP, POP3 or SMTP.
Take a look at the file header of the script. It describes how to setup the script.
---
.werks/3859 | 14 +
ChangeLog | 1 +
agents/windows/mrpe/check_mail_loop.vbs | 608 ++++++++++++++++++++++++++++++++
3 files changed, 623 insertions(+)
Diff: http://git.mathias-kettner.de/git/?p=check_mk.git;a=commitdiff;h=25b01e1c7a…