2023-07-26 15:28:44 +02:00
|
|
|
# Python: module plugintools for PandoraFMS Developers
|
|
|
|
|
2023-07-27 15:53:10 +02:00
|
|
|
pandoraPluginTools is a library that aims to help the creation of scripts and their integration in Pandora FMS.
|
2023-07-26 15:28:44 +02:00
|
|
|
|
|
|
|
[PluginTools Reference Documentation](https://pandorafms.com/guides/public/books/plugintools)
|
|
|
|
|
2023-08-22 11:49:23 +02:00
|
|
|
The package includes the following modules. Each one has different functions that facilitate and automate the data integration in Pandora FMS:
|
2023-07-27 15:53:10 +02:00
|
|
|
|
|
|
|
**general**
|
2023-07-28 11:22:02 +02:00
|
|
|
Module containing general purpose functions, useful in the creation of plugins for PandoraFMS.
|
2023-07-27 15:53:10 +02:00
|
|
|
|
|
|
|
**threads**
|
|
|
|
Module containing threading purpose functions, useful to run parallel functions.
|
2023-07-26 15:28:44 +02:00
|
|
|
|
|
|
|
**agents**
|
2023-07-27 15:53:10 +02:00
|
|
|
Module that contains functions oriented to the creation of Pandora FMS agents
|
2023-07-26 15:28:44 +02:00
|
|
|
|
|
|
|
**modules**
|
2023-07-27 15:53:10 +02:00
|
|
|
Module that contains functions oriented to the creation of Pandora FMS modules.
|
2023-07-26 15:28:44 +02:00
|
|
|
|
|
|
|
**transfer**
|
2023-07-28 11:22:02 +02:00
|
|
|
Module containing functions oriented to file transfer and data sending to Pandora FMS server.
|
2023-07-26 15:28:44 +02:00
|
|
|
|
|
|
|
**discovery**
|
2023-07-28 11:22:02 +02:00
|
|
|
Module containing functions oriented to the creation of Pandora FMS discovery plugins.
|
2023-07-26 15:28:44 +02:00
|
|
|
|
|
|
|
**http**
|
2023-07-28 11:22:02 +02:00
|
|
|
Module containing functions oriented to HTTP API calls.
|
2023-07-26 15:28:44 +02:00
|
|
|
|
2023-08-22 11:49:23 +02:00
|
|
|
## Example
|
2023-07-26 15:28:44 +02:00
|
|
|
|
2023-08-22 11:49:23 +02:00
|
|
|
```python
|
2023-07-26 15:28:44 +02:00
|
|
|
import pandoraPluginTools as ppt
|
|
|
|
|
|
|
|
## Define agent
|
|
|
|
server_name = "WIN-SERV"
|
|
|
|
|
2023-07-28 09:52:16 +02:00
|
|
|
agent=ppt.init_agent({
|
|
|
|
"agent_name" : ppt.generate_md5(server_name),
|
|
|
|
"agent_alias" : server_name,
|
|
|
|
"description" : "Default Windows server"
|
|
|
|
})
|
2023-07-26 15:28:44 +02:00
|
|
|
|
|
|
|
## Define modules
|
|
|
|
modules=[]
|
|
|
|
|
|
|
|
data = 10
|
|
|
|
modules.append({
|
|
|
|
"name" : "CPU usage",
|
|
|
|
"type" : "generic_data",
|
|
|
|
"value": data,
|
2023-07-28 10:00:40 +02:00
|
|
|
"desc" : "Percentage of CPU utilization",
|
2023-07-26 15:28:44 +02:00
|
|
|
"unit" : "%"
|
|
|
|
})
|
|
|
|
|
2023-07-28 09:59:28 +02:00
|
|
|
## Generate and transfer XML
|
|
|
|
xml_content = ppt.print_agent(agent, modules)
|
|
|
|
xml_file = ppt.write_xml(xml_content, agent["agent_name"])
|
2023-07-26 15:28:44 +02:00
|
|
|
ppt.transfer_xml(
|
2023-07-28 09:59:28 +02:00
|
|
|
xml_file,
|
2023-07-26 15:28:44 +02:00
|
|
|
transfer_mode="tentacle",
|
2023-08-01 10:40:11 +02:00
|
|
|
tentacle_ip="192.168.1.20",
|
2023-07-26 15:28:44 +02:00
|
|
|
tentacle_port="41121",
|
|
|
|
)
|
|
|
|
```
|
|
|
|
|
2023-07-27 15:53:10 +02:00
|
|
|
The package has the following dependencies:
|
2023-08-22 11:49:23 +02:00
|
|
|
|
2023-07-27 15:53:10 +02:00
|
|
|
- Hashlib
|
|
|
|
- datetime.datetime
|
|
|
|
- hashlib
|
|
|
|
- json
|
|
|
|
- os
|
|
|
|
- print_agent
|
|
|
|
- print_log_module
|
|
|
|
- print_module
|
|
|
|
- queue.Queue
|
|
|
|
- requests.auth.HTTPBasicAuth
|
|
|
|
- requests.auth.HTTPDigestAuth
|
|
|
|
- requests.sessions.Session
|
|
|
|
- requests_ntlm.HttpNtlmAuth
|
|
|
|
- shutil
|
|
|
|
- subprocess.Popen
|
|
|
|
- sys
|
|
|
|
- threading.Thread
|