Module: check_mk
Branch: master
Commit: 4665bc454c16f2b53d61047f5080abc54c1e6baf
URL: http://git.mathias-kettner.de/git/?p=check_mk.git;a=commit;h=4665bc454c16f2…
Author: Roland Halbig <rh(a)mathias-kettner.de>
Date: Thu Dec 22 12:11:51 2016 +0100
Autorefactor: Added comments and prioritized id and class attribute.
Change-Id: If13fe49b13c5ea934007e0dace5124cb2130df43
---
tests/web/auto_refactor.py | 107 +++++++++++++++++++++++++++++++--------------
1 file changed, 74 insertions(+), 33 deletions(-)
diff --git a/tests/web/auto_refactor.py b/tests/web/auto_refactor.py
index 0e4ae30..249583d 100644
--- a/tests/web/auto_refactor.py
+++ b/tests/web/auto_refactor.py
@@ -8,21 +8,6 @@ def append_to_html(html, indent, addendum):
return "%s\n%s%s" %(html, ' ' * indent, "%s" % addendum)
-def split_html(text):
- index = 1
- while index < len(text) and text[index - 1] != "(":
- index += 1
- open_braces = 1
- while index < len(text) and open_braces > 0:
- if text[index] == "(":
- open_braces += 1
- elif text[index] == ")":
- open_braces -= 1
- index += 1
- while index < len(text) and text[index] != "\n":
- index += 1
- return text[:index], text[index:]
-
def stripper(x):
x = re.sub(r' %\s+\(.*', '', x)
@@ -48,9 +33,25 @@ def preprocess_tag(tag_str):
return tag_str
-def eval_tag(tag_str, next_one, next_inbetween):
+def add_to_formated_attr_string(attrs, key, val):
+
+ if key in ["class", "id", "type", "for"]:
+ key += '_'
+
+ if attrs and key and val:
+ attrs += ", "
+
+ if isinstance(val, list):
+ val = "[\"" + "\", \"".join(val) + "\"]"
+ attrs += "%s=%s" % (key, val)
+ else:
+ attrs += "%s=\"%s\"" % (key, val)
+
+ return attrs
+# Evaluate a tag and its attributes
+def eval_tag(tag_str, next_one, next_inbetween):
skip_next = False
children = list(bs(tag_str, 'html5lib').body.children)
@@ -63,20 +64,20 @@ def eval_tag(tag_str, next_one, next_inbetween):
tag = children[0]
tag_name = tag.name
+ if "id" in tag.attrs:
+ val = tag.attrs.pop("id")
+ attrs = add_to_formated_attr_string(attrs, "id", val)
+
+ if "class" in tag.attrs:
+ val = tag.attrs.pop("class")
+ attrs = add_to_formated_attr_string(attrs, "class", val)
+
for key, val in tag.attrs.iteritems():
- if key in ["class", "id", "type", "for"]:
- key += '_'
- if attrs and key and val:
- attrs += ", "
- if isinstance(val, list):
- val = "[\"" + "\", \"".join(val) + "\"]"
- attrs += "%s=%s" % (key, val)
- else:
- attrs += "%s=\"%s\"" % (key, val)
+ attrs = add_to_formated_attr_string(attrs, key, val)
# See if we can close the tag right away
if next_one and next_one == ("</%s>" % tag_name):
- addendum = "html.%s(%s%s)" % (tag_name, next_inbetween, ", " + attrs if attrs else '')
+ addendum = "html.%s(%s%s)" % (tag_name, next_inbetween if next_inbetween else "\'\'", ", " + attrs if attrs else '')
skip_next = True
elif tag_name in ['br', 'hr', 'img']:
addendum = "html.%s(%s)" % (tag_name, attrs)
@@ -94,12 +95,15 @@ def eval_tag(tag_str, next_one, next_inbetween):
return addendum, skip_next
+# replace the input string modulo operator with [[[i]]] where i is the number
+# of the current string modulo operator
def replace_inputs(text, inputs):
for index, input in enumerate(inputs):
text = re.sub("%" + "s", '[[[%s]]]' % index, text, 1)
return text
+# insert the inputs into the fields where the [[[i]]] space holders are
def insert_inputs(text, inputs):
if not inputs:
return text
@@ -116,12 +120,36 @@ def insert_inputs(text, inputs):
text = re.sub(r"[[]{3}%s[]]{3}" % counter, '%' + 's' + '\" % ' + input + "\"", text, 1)
return text
+
def test_replace_inputs():
text = "<tag class=\"ein %s\" id=%s>%s</tag>"
inputs = ["test", "id", "Hallo Welt!"]
print replace_inputs(text, inputs)
+# Text extraction
+def find_end_of_first_expression(text):
+ index = 1
+ while index < len(text) and text[index - 1] != "(":
+ index += 1
+ open_braces = 1
+ while index < len(text) and open_braces > 0:
+ if text[index] == "(":
+ open_braces += 1
+ elif text[index] == ")":
+ open_braces -= 1
+ index += 1
+ while index < len(text) and text[index] != "\n":
+ index += 1
+ return index
+
+
+# Split text into a part to refactor and a rest part
+def split_html(text):
+ index = find_end_of_first_expression(text)
+ return text[:index], text[index:]
+
+
# this function does a big chunk of the refactoring for me
def replace_tags(html, indent = 0):
@@ -138,9 +166,11 @@ def replace_tags(html, indent = 0):
if " % " in html and len(html.split(" % ")) != 2:
return html
+ # split into code to refactor and rest
html, rest = split_html(html)
orig_html = html
+ # for string inputs find the input arguments
inputs = []
if " % " in html or ' %\n' in html:
if " % " in html:
@@ -155,9 +185,11 @@ def replace_tags(html, indent = 0):
inbetween = re.split(r'<[^<]*>', re.sub(r'\s*html\.write\([\'|"]?', '', html, 1))
inbetween = map(stripper, inbetween)
+ # if no tags are found, then return unchanged code
if len(tags) == 0:
return orig_html + rest
+ # First result which is not a tag
html = ''
if inbetween[0].strip(' ') not in ['', '\n']:
html = append_to_html(html, indent, "html.write(%s)" % inbetween[0])
@@ -178,12 +210,13 @@ def replace_tags(html, indent = 0):
elif skip_next and addendum.strip(' '):
counter += 1
+ # Now indest the pipes
html = insert_inputs(html, inputs)
for index, input in enumerate(inputs):
if "[[[%s]]]" % index in html:
html = re.sub("[[[%s]]]" % index, input, html)
-
+ # Print string
try:
return orig_html + "\n(new)" + html + rest
except:
@@ -195,27 +228,35 @@ def replace_tags(html, indent = 0):
return orig_html + "\n(new)" + html + "\n" + rest
+# indent of a text part which was created using split(html.write).
+# This means the indent of the next code block is to be found at the end of the previous block.
+def get_indent(text):
+ indent = 0
+ while indent < len(text) and text[len(text) - 1 - indent] == ' ':
+ indent += 1
+ return indent
+
if __name__ == "__main__":
html = sys.argv[1]
if html.endswith('.py'):
+
whole_text = ''
with open(html, 'r') as rfile:
whole_text = "".join(line for line in rfile)
+
parts = whole_text.split("html.write(")
with open("refactored_file.py", "w") as wfile:
part = parts.pop(0)
wfile.write(part)
- indent = 0
- while indent < len(part) and part[len(part) - 1 - indent] == ' ':
- indent += 1
+
+ indent = get_indent(part)
for part in parts:
part = "html.write(" + part
wfile.write(replace_tags(part, indent))
- indent = 0
- while indent < len(part) and part[len(part) - 1 - indent] == ' ':
- indent += 1
+ indent = get_indent(part)
+
elif html == "test":
test_replace_inputs()
else:
Module: check_mk
Branch: master
Commit: eb8236280e179f3cfb0341015a828d7bc73e8a15
URL: http://git.mathias-kettner.de/git/?p=check_mk.git;a=commit;h=eb8236280e179f…
Author: Lars Michelsen <lm(a)mathias-kettner.de>
Date: Thu Dec 22 09:51:10 2016 +0100
4219: Trap processing with community "public" is now only default and not accepted in all cases anymore
Change-Id: I40052ccaff7db6d3c1525c3337ec5ba3a0380f5f
---
.werks/4219 | 15 +++++++++++++++
ChangeLog | 2 ++
bin/mkeventd | 10 ++++++----
web/plugins/wato/mkeventd.py | 6 ++++++
4 files changed, 29 insertions(+), 4 deletions(-)
diff --git a/.werks/4219 b/.werks/4219
new file mode 100644
index 0000000..1ee574f
--- /dev/null
+++ b/.werks/4219
@@ -0,0 +1,15 @@
+Title: Trap processing with community "public" is now only default and not accepted in all cases anymore
+Level: 1
+Component: ec
+Compatible: incomp
+Version: 1.4.0i4
+Date: 1482396336
+Class: fix
+
+Since several versions you can configure the Event Console to receive only SNMP traps having
+specific SNMP communities set. Previous versions were simply processing all traps.
+
+The community "public" was somehow special since traps with this community were accepted in
+any cases. We have now changed the community public to just be accepted by default. In case
+you add additional communities, these will also be accepted. But in the moment you remove
+the public community, the traps containing this community will not be accepted anymore.
diff --git a/ChangeLog b/ChangeLog
index 2bee0d3..2b44839 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -45,6 +45,8 @@
* 4156 FIX: Fix off-by-one error in EC limit handling...
* 4199 FIX: Fix detection of replication mode if EC is distributed...
* 4200 FIX: Fix computation of Event Console performance snapin in distributed mode...
+ * 4219 FIX: Trap processing with community "public" is now only default and not accepted in all cases anymore...
+ NOTE: Please refer to the migration notes!
1.4.0i3:
diff --git a/bin/mkeventd b/bin/mkeventd
index c18d043..9bad547 100755
--- a/bin/mkeventd
+++ b/bin/mkeventd
@@ -468,9 +468,6 @@ def initialize_snmptrap_engine():
def initialize_snmp_credentials():
- # Add default v1/v2 config to make v1/v2 trap porcessing work
- snmp_config.addV1System(g_snmp_engine, 'my-area', 'public')
-
user_num = 0
for spec in g_config["snmp_credentials"]:
credentials = spec["credentials"]
@@ -4501,7 +4498,12 @@ def default_config():
"archive_orphans" : False,
"archive_mode" : "file",
"translate_snmptraps" : False,
- "snmp_credentials" : [],
+ "snmp_credentials" : [
+ {
+ "description": "\"public\" default for receiving SNMPv1/v2 traps",
+ "credentials": "public",
+ },
+ ],
"event_limit" : {
'by_host': {
'action': 'stop_overflow_notify',
diff --git a/web/plugins/wato/mkeventd.py b/web/plugins/wato/mkeventd.py
index 2542c02..df7674f 100644
--- a/web/plugins/wato/mkeventd.py
+++ b/web/plugins/wato/mkeventd.py
@@ -2677,6 +2677,12 @@ if mkeventd_enabled:
help = _("When you want to process SNMP traps with the Event Console it is "
"necessary to configure the credentials to decrypt the incoming traps."),
text_if_empty = _("SNMP traps not configured"),
+ default_value = [
+ {
+ "description": _("\"public\" default for receiving SNMPv1/v2 traps"),
+ "credentials": "public",
+ },
+ ],
),
domain = ConfigDomainEventConsole,
)