add readme.md and minor changes

This commit is contained in:
alejandro 2023-07-26 15:28:44 +02:00
parent b70be8b4e6
commit b526b10200
3 changed files with 138 additions and 30 deletions

View File

@ -0,0 +1,88 @@
# Python: module plugintools for PandoraFMS Developers
pandoraPluginTools is a library that aims to help the creation of scripts and their integration in PandoraFMS.
[PluginTools Reference Documentation](https://pandorafms.com/guides/public/books/plugintools)
The package includes the following modules: agents, modules, transfer, general, discovery and http. Each one has different requirements and functions that facilitate and automate the data integration in PandoraFMS. They have the following dependencies :
**agents**
Module that contains functions oriented to the creation of agents.
- datetime.datetime
- subprocess.Popen
- Hashlib
- sys
- os
- print_module
- print_log_module
**modules**
Module that contains functions oriented to the creation of modules.
**transfer**
Module containing functions oriented to file transfer and data sending.
- datetime.datetime
- subprocess.Popen
- shutil
- sys
- os
- print_agent
**general**
Module containing general purpose functions, useful in the creation of plugins for PandoraFMS.
- datetime.datetime
- hashlib
- json
- sys
**discovery**
Module that contains general purpose functions, useful in the creation of plugins for PandoraFMS discovery.
- json
- sys
**http**
Module that contains general purpose functions, useful in the creation of plugins for PandoraFMS discovery.
- requests_ntlm.HttpNtlmAuth
- requests.auth.HTTPBasicAuth
- requests.auth.HTTPDigestAuth
- requests.sessions.Session
## Example
``` python
import pandoraPluginTools as ppt
## Define agent
server_name = "WIN-SERV"
agent=ppt.agents.init_agent()
agent.update(
agent_name = ppt.generate_md5(server_name),
agent_alias = server_name,
description = "Default Windows server",
)
## Define modules
modules=[]
data = 10
modules.append({
"name" : "CPU usage",
"type" : "generic_data",
"value": data,
"desc" : "percentage of cpu utilization",
"unit" : "%"
})
## Transfer XML
ppt.transfer_xml(
agent,
modules,
transfer_mode="tentacle",
tentacle_address="192.168.1.20",
tentacle_port="41121",
temporal="/tmp"
)
```

View File

@ -2,6 +2,7 @@ from datetime import datetime
from subprocess import * from subprocess import *
import hashlib import hashlib
import sys import sys
import os
from .modules import print_module,print_log_module from .modules import print_module,print_log_module
global_variables = { global_variables = {
@ -9,6 +10,21 @@ global_variables = {
'agents_group_name': '', 'agents_group_name': '',
'interval' : 300 'interval' : 300
} }
#########################################################################################
# OS check
#########################################################################################
POSIX = os.name == "posix"
WINDOWS = os.name == "nt"
LINUX = sys.platform.startswith("linux")
MACOS = sys.platform.startswith("darwin")
OSX = MACOS # deprecated alias
FREEBSD = sys.platform.startswith("freebsd")
OPENBSD = sys.platform.startswith("openbsd")
NETBSD = sys.platform.startswith("netbsd")
BSD = FREEBSD or OPENBSD or NETBSD
SUNOS = sys.platform.startswith(("sunos", "solaris"))
AIX = sys.platform.startswith("aix")
#### ####
# Set a global variable with the specified name and assigns a value to it. # Set a global variable with the specified name and assigns a value to it.
@ -118,3 +134,19 @@ def init_agent() :
"agent_mode" : "1", "agent_mode" : "1",
} }
return agent return agent
#########################################################################################
# Agent class
#########################################################################################
class Agent:
"""Basic agent class. Requires agent parameters (config {dictionary})
and module definition (modules_def [list of dictionaries]) """
def __init__(
self,
config,
modules_def
):
self.config = config
self.modules_def = modules_def

View File

@ -2,37 +2,8 @@ import sys
import os import os
import json import json
from datetime import datetime from datetime import datetime
import hashlib
#########################################################################################
# OS check
#########################################################################################
POSIX = os.name == "posix"
WINDOWS = os.name == "nt"
LINUX = sys.platform.startswith("linux")
MACOS = sys.platform.startswith("darwin")
OSX = MACOS # deprecated alias
FREEBSD = sys.platform.startswith("freebsd")
OPENBSD = sys.platform.startswith("openbsd")
NETBSD = sys.platform.startswith("netbsd")
BSD = FREEBSD or OPENBSD or NETBSD
SUNOS = sys.platform.startswith(("sunos", "solaris"))
AIX = sys.platform.startswith("aix")
#########################################################################################
# Agent class
#########################################################################################
class Agent:
"""Basic agent class. Requires agent parameters (config {dictionary})
and module definition (modules_def [list of dictionaries]) """
def __init__(
self,
config,
modules_def
):
self.config = config
self.modules_def = modules_def
######################################################################################### #########################################################################################
# Debug_dict: prints dictionary in formatted json string. # Debug_dict: prints dictionary in formatted json string.
@ -154,3 +125,20 @@ def parse_csv_file(
except Exception as e: except Exception as e:
print (f"{type(e).__name__}: {e}") print (f"{type(e).__name__}: {e}")
return 1 return 1
#########################################################################################
# md5 generator
#########################################################################################
def generate_md5(input_string):
"""
Generates an MD5 hash for the given input string.
Args:
input_string (str): The string for which the MD5 hash will be generated.
Returns:
str: The MD5 hash of the input string as a hexadecimal string.
"""
md5_hash = hashlib.md5(input_string.encode()).hexdigest()
return md5_hash