Module: check_mk
Branch: master
Commit: 40f25d78072f1f1ca4a45746778d1d821d4606a1
URL: http://git.mathias-kettner.de/git/?p=check_mk.git;a=commit;h=40f25d78072f1f…
Author: Moritz Kiemer <mo(a)mathias-kettner.de>
Date: Thu Nov 8 14:17:48 2018 +0100
wmi.include: Refactor inventory function
Split up 'inventory_wmi_table' function into two separate
functions 'inventory_wmi_table_instance' (with strings as items)
and 'inventory_wmi_table_total' (with None as only item).
Change-Id: I8d963ccc56dc14c672800811c4923165a1fe0cf5
---
checks/wmi.include | 62 ++++++++++++++++++++++++++++++++++++++++++------------
checks/wmi_cpuload | 4 +---
2 files changed, 49 insertions(+), 17 deletions(-)
diff --git a/checks/wmi.include b/checks/wmi.include
index 8162ee0..9b746de 100644
--- a/checks/wmi.include
+++ b/checks/wmi.include
@@ -251,13 +251,17 @@ def wmi_filter_global_only(tables, row):
# | |___/ |
# '----------------------------------------------------------------------'
+def _required_tables_missing(tables, required_tables):
+ is_subset = set(required_tables).issubset(set(tables.keys()))
+ contains_null = any(isinstance(table, NullTable) for table in tables.itervalues())
+ return not is_subset or contains_null
-def inventory_wmi_table(tables, **kwargs):
- required_tables = kwargs.get('required_tables', tables.keys())
- if (not set(required_tables) <= set(tables.keys()) or
- any(isinstance(table, NullTable) for table in tables.itervalues())):
- # if table is missing, nothing gets inventorized. This can
- # only happen if required_tables was set
+
+def inventory_wmi_table_instances(tables, required_tables=None, filt=None, levels=None):
+ if required_tables is None:
+ required_tables = tables.keys()
+
+ if _required_tables_missing(tables, required_tables):
return []
potential_instances = set()
@@ -269,16 +273,46 @@ def inventory_wmi_table(tables, **kwargs):
else:
potential_instances = set(table_rows)
- # if there are multiple instances, don't include the summary line as it is redundant
- if len(potential_instances) > 1:
- potential_instances.discard(None)
+ # don't include the summary line
+ potential_instances.discard(None)
+
+ return [(row, levels) for row in potential_instances if filt is None or filt(tables, row)]
+
+
+
+def inventory_wmi_table_total(tables, required_tables=None, filt=None, levels=None):
+ if required_tables is None:
+ required_tables = tables.keys()
+
+ if not tables or _required_tables_missing(tables, required_tables):
+ return []
+
+ if filt is not None and not filt(tables, None):
+ return []
+
+ total_present = all(None in tables[required_table].row_labels()
+ for required_table in required_tables)
+
+ if not total_present:
+ return []
+ return [(None, levels)]
+
+
+def inventory_wmi_table(tables, required_tables=None, filt=None, levels=None):
+ '''DO NOT USE
+
+ Please use either inventory_wmi_table_instances or inventory_wmi_table_total
+ directly. This function sometimes returns strings and sometimes None as an item.
+ '''
+ instances = inventory_wmi_table_instances(tables, required_tables, filt, levels)
+ if instances:
+ return instances
- # apply row-filter if the caller provided one
- filt = kwargs.get('filt', lambda tables, row: True)
+ total = inventory_wmi_table_total(tables, required_tables, filt, levels)
+ if total:
+ return total
- return [(row, kwargs.get('levels', None))
- for row in potential_instances
- if filt(tables, row)]
+ return []
#.
diff --git a/checks/wmi_cpuload b/checks/wmi_cpuload
index a4dc9ed..607ee4d 100644
--- a/checks/wmi_cpuload
+++ b/checks/wmi_cpuload
@@ -26,9 +26,7 @@
def inventory_wmi_cpuload(tables):
- if ("computer_system" not in tables.keys() or
- "system_perf" not in tables.keys() or
- any(isinstance(table, NullTable) for table in tables.itervalues())):
+ if _required_tables_missing(tables, ["computer_system", "system_perf"]):
return []
return [(None, None)]
Module: check_mk
Branch: master
Commit: a92281874c45f5657d7ab2f31f6665b66032b8b7
URL: http://git.mathias-kettner.de/git/?p=check_mk.git;a=commit;h=a92281874c45f5…
Author: Sergey Kipnis <sk(a)mathias-kettner.de>
Date: Tue Nov 6 16:42:56 2018 +0100
[CMK-1039] - perfreader into master
- PerfCounter.cc has optional possibility to find and run perf_reader.exe
- check_mk_agent is supplied in "perfread" parameter to test functionality
- service home folder is found from the service control routine
- sln, vcxproj* files and test_workbench project are Windows only(ignore those files if you are not in Visual Studio 2017)
- typo MSVC_BUILD fixed
- ModuleControl.h added to find and run executables in windows environment
- perf_reader.exe, .gitignore and readme.txt placed into doc/treasures/windows
- readme.txt fixed, removed disabled test output
6862 FIX Fixed Handle Leak in Windows Agent
To prevent handle leaks in Windows Agent for certain versions of Windows OS
provided perf_reader.exe utility in ~/share/doc/check_mk/treasures/windows directory.
Short description can be found ~/share/doc/check_mk/treasures/windows/readme.txt
Change-Id: I14046e6dc9859d73a77d134f6eb20c3e8ffe9a19
---
.werks/6862 | 12 +
agents/windows/Environment.h | 6 +
agents/windows/ModuleControl.h | 261 ++++++++++
agents/windows/PerfCounter.cc | 102 +++-
agents/windows/WinApiInterface.h | 6 +-
agents/windows/check_mk_agent.cc | 75 ++-
agents/windows/check_mk_agent.sln | 31 ++
agents/windows/check_mk_agent.vcxproj | 537 +++++++++++++++++++++
agents/windows/check_mk_agent.vcxproj.filters | 306 ++++++++++++
agents/windows/tools/_raii.h | 70 +++
agents/windows/utils/perf_reader/pch.cpp | Bin 0 -> 430 bytes
agents/windows/utils/perf_reader/pch.h | Bin 0 -> 1582 bytes
agents/windows/utils/perf_reader/perf_reader.cpp | Bin 0 -> 11940 bytes
agents/windows/utils/perf_reader/perf_reader.sln | 31 ++
.../windows/utils/perf_reader/perf_reader.vcxproj | 187 +++++++
.../utils/perf_reader/perf_reader.vcxproj.filters | 33 ++
.../windows/utils/perf_reader/test_perf_reader.cmd | 14 +
agents/windows/utils/readme.md | 1 +
agents/windows/utils/test_workbench/pch.cpp | Bin 0 -> 430 bytes
agents/windows/utils/test_workbench/pch.h | Bin 0 -> 1262 bytes
agents/windows/utils/test_workbench/readme.md | 1 +
.../utils/test_workbench/test_workbench.cpp | Bin 0 -> 6580 bytes
.../utils/test_workbench/test_workbench.sln | 31 ++
.../utils/test_workbench/test_workbench.vcxproj | 199 ++++++++
.../test_workbench/test_workbench.vcxproj.filters | 36 ++
doc/treasures/windows/.gitignore | 1 +
doc/treasures/windows/perf_reader.exe | Bin 0 -> 112128 bytes
doc/treasures/windows/readme.txt | 13 +
28 files changed, 1930 insertions(+), 23 deletions(-)
Diff: http://git.mathias-kettner.de/git/?p=check_mk.git;a=commitdiff;h=a92281874c…