pandoraPlugintools-basic 1.0.3__tar.gz → 1.1.0__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (20) hide show
  1. {pandoraplugintools_basic-1.0.3/pandoraPlugintools_basic.egg-info → pandoraplugintools_basic-1.1.0}/PKG-INFO +3 -1
  2. {pandoraplugintools_basic-1.0.3 → pandoraplugintools_basic-1.1.0}/README.md +2 -0
  3. {pandoraplugintools_basic-1.0.3 → pandoraplugintools_basic-1.1.0}/pandoraPlugintools/__init__.py +2 -1
  4. {pandoraplugintools_basic-1.0.3 → pandoraplugintools_basic-1.1.0}/pandoraPlugintools/discovery.py +1 -1
  5. {pandoraplugintools_basic-1.0.3 → pandoraplugintools_basic-1.1.0}/pandoraPlugintools/general.py +3 -3
  6. {pandoraplugintools_basic-1.0.3 → pandoraplugintools_basic-1.1.0}/pandoraPlugintools/modules.py +7 -3
  7. pandoraplugintools_basic-1.1.0/pandoraPlugintools/monitoring.py +86 -0
  8. {pandoraplugintools_basic-1.0.3 → pandoraplugintools_basic-1.1.0/pandoraPlugintools_basic.egg-info}/PKG-INFO +3 -1
  9. {pandoraplugintools_basic-1.0.3 → pandoraplugintools_basic-1.1.0}/pandoraPlugintools_basic.egg-info/SOURCES.txt +1 -0
  10. {pandoraplugintools_basic-1.0.3 → pandoraplugintools_basic-1.1.0}/setup.cfg +1 -1
  11. {pandoraplugintools_basic-1.0.3 → pandoraplugintools_basic-1.1.0}/setup.py +1 -1
  12. pandoraplugintools_basic-1.1.0/tests/test_basic.py +12 -0
  13. pandoraplugintools_basic-1.0.3/tests/test_basic.py +0 -2
  14. {pandoraplugintools_basic-1.0.3 → pandoraplugintools_basic-1.1.0}/LICENSE +0 -0
  15. {pandoraplugintools_basic-1.0.3 → pandoraplugintools_basic-1.1.0}/pandoraPlugintools/agents.py +0 -0
  16. {pandoraplugintools_basic-1.0.3 → pandoraplugintools_basic-1.1.0}/pandoraPlugintools/output.py +0 -0
  17. {pandoraplugintools_basic-1.0.3 → pandoraplugintools_basic-1.1.0}/pandoraPlugintools/threads.py +0 -0
  18. {pandoraplugintools_basic-1.0.3 → pandoraplugintools_basic-1.1.0}/pandoraPlugintools/transfer.py +0 -0
  19. {pandoraplugintools_basic-1.0.3 → pandoraplugintools_basic-1.1.0}/pandoraPlugintools_basic.egg-info/dependency_links.txt +0 -0
  20. {pandoraplugintools_basic-1.0.3 → pandoraplugintools_basic-1.1.0}/pandoraPlugintools_basic.egg-info/top_level.txt +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: pandoraPlugintools-basic
3
- Version: 1.0.3
3
+ Version: 1.1.0
4
4
  Summary: A plugin tool set of basic functions for pandorafms
5
5
  Home-page: https://github.com/pandorafms/pandoraPlugintoolsBasic
6
6
  Author: PandoraFMS projects department
@@ -55,6 +55,8 @@ The package exports the following modules:
55
55
  Reference documentation:
56
56
  [PluginTools Reference Documentation](https://pandorafms.com/guides/public/books/plugintools)
57
57
 
58
+ For a full, runnable example per function, see [docs/examples.md](docs/examples.md).
59
+
58
60
  ## Most used functions
59
61
 
60
62
  The README stays focused on the quick path. For a complete function list and full details, use the reference documentation link above.
@@ -38,6 +38,8 @@ The package exports the following modules:
38
38
  Reference documentation:
39
39
  [PluginTools Reference Documentation](https://pandorafms.com/guides/public/books/plugintools)
40
40
 
41
+ For a full, runnable example per function, see [docs/examples.md](docs/examples.md).
42
+
41
43
  ## Most used functions
42
44
 
43
45
  The README stays focused on the quick path. For a complete function list and full details, use the reference documentation link above.
@@ -4,4 +4,5 @@ from .threads import *
4
4
  from .agents import *
5
5
  from .modules import *
6
6
  from .transfer import *
7
- from .discovery import *
7
+ from .discovery import *
8
+ from .monitoring import *
@@ -60,7 +60,7 @@ def set_disco_summary(data: dict = {}) -> None:
60
60
  """
61
61
  global _SUMMARY
62
62
 
63
- _SUMMARY = {}
63
+ _SUMMARY = data
64
64
 
65
65
 
66
66
  ####
@@ -315,13 +315,13 @@ def _print_debug(var="", print_errors: bool = False):
315
315
  #########################################################################################
316
316
  def safe_input(input_string: str = "") -> str:
317
317
  """
318
- Convert an input string encoded in HTML entities to a clear character string.
318
+ Convert special characters in an input string to their corresponding HTML entities.
319
319
 
320
320
  Args:
321
- input_string (str): The input string encoded in HTML entities.
321
+ input_string (str): The input string containing characters to encode.
322
322
 
323
323
  Returns:
324
- str: The decoded clear character string.
324
+ str: The encoded string with special characters replaced by HTML entities.
325
325
  """
326
326
  if not input_string:
327
327
  return ""
@@ -86,6 +86,13 @@ def init_module(
86
86
  if key in module:
87
87
  module[key] = value
88
88
 
89
+ # Compatibility alias: whichever of 'data'/'value' the caller explicitly
90
+ # set, mirror it onto the other one if that other one was not also set.
91
+ if "data" in default_values and "value" not in default_values:
92
+ module["value"] = module["data"]
93
+ elif "value" in default_values and "data" not in default_values:
94
+ module["data"] = module["value"]
95
+
89
96
  return module
90
97
 
91
98
  ####
@@ -115,9 +122,6 @@ def print_module(
115
122
  if "description" in data:
116
123
  data["desc"] = data["description"]
117
124
 
118
- if "data" in data:
119
- data["value"] = data["data"]
120
-
121
125
  module_xml = ("<module>\n"
122
126
  "\t<name><![CDATA[" + str(data["name"]) + "]]></name>\n"
123
127
  "\t<type>" + str(data["type"]) + "</type>\n"
@@ -0,0 +1,86 @@
1
+ import json
2
+
3
+ ####
4
+ # Define some global variables
5
+ #########################################################################################
6
+
7
+ _MONITORING_ITEMS = []
8
+
9
+ ####
10
+ # Set fixed list of monitoring items
11
+ #########################################################################################
12
+ def set_monitoring_items(data: list = []) -> None:
13
+ """
14
+ Sets the monitoring items list to the specified value.
15
+
16
+ Args:
17
+ data (list): A list of monitoring item dicts, each with 'agent_data'
18
+ and 'module_data' keys, as accepted by the '/monitoring' API endpoint.
19
+
20
+ Returns:
21
+ None
22
+ """
23
+ global _MONITORING_ITEMS
24
+
25
+ _MONITORING_ITEMS = data
26
+
27
+
28
+ ####
29
+ # Add one monitoring item (agent_data + module_data)
30
+ #########################################################################################
31
+ def add_monitoring_item(agent_data: dict = {}, module_data: list = []) -> None:
32
+ """
33
+ Adds one monitoring item to the internal monitoring items list.
34
+
35
+ Builds a single entry of the '/monitoring' API payload array from an
36
+ agent dict and a list of module dicts. Both are plain dicts the caller
37
+ already built (e.g. via 'init_agent()'/'init_module()' or by hand);
38
+ this function does not validate or transform their shape.
39
+
40
+ Args:
41
+ agent_data (dict): A dictionary containing agent configuration.
42
+ module_data (list): A list of dictionaries representing modules.
43
+
44
+ Returns:
45
+ None
46
+ """
47
+ global _MONITORING_ITEMS
48
+
49
+ _MONITORING_ITEMS.append({"agent_data": agent_data, "module_data": module_data})
50
+
51
+
52
+ ####
53
+ # Get monitoring items
54
+ #########################################################################################
55
+ def get_monitoring_items() -> list:
56
+ """
57
+ Retrieves the current monitoring items list.
58
+
59
+ Returns:
60
+ list: The list of monitoring items accumulated so far.
61
+ """
62
+ return _MONITORING_ITEMS
63
+
64
+
65
+ ####
66
+ # Build (and optionally print) the monitoring API payload as JSON
67
+ #########################################################################################
68
+ def print_monitoring_payload(print_flag: bool = False) -> str:
69
+ """
70
+ Build the JSON array ready to be sent as the request body to the
71
+ '/monitoring' API endpoint, optionally printing it.
72
+
73
+ Args:
74
+ print_flag (bool): A flag indicating whether to print the JSON payload.
75
+
76
+ Returns:
77
+ str: The JSON representation of the monitoring items list.
78
+ """
79
+ json_string = json.dumps(_MONITORING_ITEMS)
80
+
81
+ if print_flag:
82
+ from .output import print_stdout
83
+
84
+ print_stdout(json_string)
85
+
86
+ return json_string
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: pandoraPlugintools-basic
3
- Version: 1.0.3
3
+ Version: 1.1.0
4
4
  Summary: A plugin tool set of basic functions for pandorafms
5
5
  Home-page: https://github.com/pandorafms/pandoraPlugintoolsBasic
6
6
  Author: PandoraFMS projects department
@@ -55,6 +55,8 @@ The package exports the following modules:
55
55
  Reference documentation:
56
56
  [PluginTools Reference Documentation](https://pandorafms.com/guides/public/books/plugintools)
57
57
 
58
+ For a full, runnable example per function, see [docs/examples.md](docs/examples.md).
59
+
58
60
  ## Most used functions
59
61
 
60
62
  The README stays focused on the quick path. For a complete function list and full details, use the reference documentation link above.
@@ -7,6 +7,7 @@ pandoraPlugintools/agents.py
7
7
  pandoraPlugintools/discovery.py
8
8
  pandoraPlugintools/general.py
9
9
  pandoraPlugintools/modules.py
10
+ pandoraPlugintools/monitoring.py
10
11
  pandoraPlugintools/output.py
11
12
  pandoraPlugintools/threads.py
12
13
  pandoraPlugintools/transfer.py
@@ -1,7 +1,7 @@
1
1
  [metadata]
2
2
  license_file = LICENSE
3
3
  description_file = README.md
4
- version = 1.0.3
4
+ version = 1.1.0
5
5
 
6
6
  [egg_info]
7
7
  tag_build =
@@ -8,7 +8,7 @@ with open("README.md", mode="r", encoding="utf-8") as f:
8
8
 
9
9
  setup(
10
10
  name="pandoraPlugintools-basic",
11
- version="1.0.3",
11
+ version="1.1.0",
12
12
  author="PandoraFMS projects department",
13
13
  author_email="<info@pandorafms.com>",
14
14
  description="A plugin tool set of basic functions for pandorafms",
@@ -0,0 +1,12 @@
1
+ import pandoraPlugintools as ppt
2
+
3
+ m = ppt.init_module({"name": "x", "value": "10"})
4
+ assert "<data><![CDATA[10]]></data>" in ppt.print_module(m)
5
+
6
+ ppt.set_monitoring_items([])
7
+ ppt.add_monitoring_item({"agent_name": "host1"}, [{"name": "CPU", "type": "generic_data", "data": 30}])
8
+ payload = ppt.print_monitoring_payload()
9
+ assert '"agent_data"' in payload and '"module_data"' in payload
10
+ ppt.set_monitoring_items([])
11
+
12
+ print("ok")
@@ -1,2 +0,0 @@
1
- import pandoraPlugintools
2
- print("ok")