Module: check_mk
Branch: master
Commit: 4077ba19ad7fd8f5dfeeb705d35eb71baa80a9ef
URL:
http://git.mathias-kettner.de/git/?p=check_mk.git;a=commit;h=4077ba19ad7fd8…
Author: Andreas Umbreit <au(a)mathias-kettner.de>
Date: Tue Mar 7 08:19:27 2017 +0100
Combined graphs: New class AutomaticDict
Adding new module containers to lib, including new class
AutomaticDict. This class derives from OrderedDict and
provides list-like appending while generating an
automatic key.
---
lib/containers.py | 48 ++++++++++++++++++++++++++++++++++++++++++++++++
web/htdocs/metrics.py | 8 +++++---
2 files changed, 53 insertions(+), 3 deletions(-)
diff --git a/lib/containers.py b/lib/containers.py
new file mode 100644
index 0000000..f8ae783
--- /dev/null
+++ b/lib/containers.py
@@ -0,0 +1,48 @@
+#!/usr/bin/python
+# -*- encoding: utf-8; py-indent-offset: 4 -*-
+# +------------------------------------------------------------------+
+# | ____ _ _ __ __ _ __ |
+# | / ___| |__ ___ ___| | __ | \/ | |/ / |
+# | | | | '_ \ / _ \/ __| |/ / | |\/| | ' / |
+# | | |___| | | | __/ (__| < | | | | . \ |
+# | \____|_| |_|\___|\___|_|\_\___|_| |_|_|\_\ |
+# | |
+# | Copyright Mathias Kettner 2014 mk(a)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.
+
+# This file contains special containers needed for data representation
+
+from collections import OrderedDict
+
+# Dictionary class with the ability of appending items like provided
+# by a list.
+class AutomaticDict(OrderedDict):
+
+ def __init__(self, list_identifier = None, start_index = None):
+ OrderedDict.__init__(self)
+ self._list_identifier = list_identifier or "item"
+ self._item_index = start_index or 0
+
+ def __getitem__(self, item):
+ if item in self.keys():
+ return OrderedDict.__getitem__(self, item)
+ else:
+ return self["%s_%i" %(self._list_identifier, item)]
+
+ def append(self, item):
+ self["%s_%i" %(self._list_identifier, self._item_index)] = item
+ self._item_index += 1
diff --git a/web/htdocs/metrics.py b/web/htdocs/metrics.py
index d51a57f..f300256 100644
--- a/web/htdocs/metrics.py
+++ b/web/htdocs/metrics.py
@@ -33,17 +33,17 @@
# unit_name: The ID of a unit, e.g. "%"
# unit: The definition-dict of a unit like in unit_info
# graph_template: Template for a graph. Essentially a dict with the key
"metrics"
-
import math, time, colorsys, shlex, operator, random
import config, pagetypes, table
import sites
import traceback
+from collections import OrderedDict
from log import logger
from lib import *
from valuespec import *
import livestatus
from cmk.regex import regex
-from collections import OrderedDict
+from cmk.containers import AutomaticDict
try:
import simplejson as json
@@ -72,7 +72,9 @@ def load_plugins(force):
global metric_info ; metric_info = {}
global check_metrics ; check_metrics = {}
global perfometer_info ; perfometer_info = []
- global graph_info ; graph_info = OrderedDict()
+ # mk_collections.AutomaticDict is used here to provide some list methods.
+ # This is needed to maintain backwards-compatibility.
+ global graph_info ; graph_info =
AutomaticDict("manual_graph_template")
load_web_plugins("metrics", globals())
loaded_with_language = current_language