A plugin tool set of functions for pandorafms
Project description
Python: module plugintools for PandoraFMS Developers
Example
import pandoraPlugintools as pt
# Agent example
agent_data = {
"agent_name" : "agentname",
"agent_alias" : "alias",
"parent_agent_name" : "parent agent",
"description" : "agente de pruebas",
"version" : "v756",
"os_name" : "Windows",
"os_version" : "10",
"timestamp" : datetime.today().strftime('%Y/%m/%d %H:%M:%S'),
"address" : "127.0.0.1",
"group" : "Servers",
"interval" : "300",
}
modules = [{
"name" : "test1",
"type" : "generic_data",
"value" : 12344
},{
"name" : "test2",
"type" : "generic_data_string",
"value" : "test"
}]
# test example translate macros
macros = {
'_test_': 'Prueba',
'_agent_name_':'pandora_agent'
}
string = '_test_ macro translator to agent _agent_name_'
print (pt.translate_macros(macros, string))
# Print Agent
test_agent = pt.print_agent(agent_data, modules,data_dir='/tmp/', print_flag=0)
# Define tentacle conf
tentacle_conf = {
'address' : 'server.pandora.com',
'port' : '41121',
#'password' : 'pass'
}
# Send datafile file
if test_agent[1] is not None:
pt.tentacle_xml(test_agent[1], tentacle_conf, debug=0)
Dependencies
Classes
class Agent(builtins.object)
Basic agent class. Requires agent parameters (config {dictionary})
and module definition (modules_def [list of dictionaries])
Methods defined here:
__init__(self, config, modules_def)
Initialize self. See help(type(self)) for accurate signature.
Data descriptors defined here:
__dict__
dictionary for instance variables (if defined)
__weakref__
list of weak references to the object (if defined)
Functions
auth_call(session, authtype, user, passw)
Authentication for url request. Requires request.sessions.Session() object.
Args:
- session (object): request Session() object.
- authtype (str): 'ntlm', 'basic' or 'digest'.
- user (str): auth user.
- passw (str): auth password.
call_url(url, authtype, user, passw, time_out)
Call URL. Uses request module to get url contents.
Args:
- url (str): URL
- authtype (str): ntlm', 'basic', 'digest'. Optional.
- user (str): auth user. Optional.
- passw (str): auth password. Optional.
Returns:
- str: call output
debug_dict(func)
debug_dict [Decorator]. Prints an indented json.
Write @debug_dict above any function that returns a dictionary or a list of dictionaries.
now(print_flag=None, utimestamp=None)
Returns time in yyyy/mm/dd HH:MM:SS format by default. Use 1 as an argument
to get epoch time (utimestamp)
parse_configuration(file='/etc/pandora/pandora_server.conf', separator=' ')
Parse configuration. Reads configuration file and stores its data as dict.
Args:
- file (str): configuration file path. Defaults to "/etc/pandora/pandora_server.conf".
- separator (str, optional): Separator for option and value. Defaults to " ".
Returns:
- dict: containing all keys and values from file.
print_agent(agent, modules, data_dir='/var/spool/pandora/data_in/', log_modules=None, print_flag=None)
Prints agent XML. Requires agent conf (dict) and modules (list) as arguments.
- Use print_flag to show modules' XML in STDOUT.
- Returns a tuple (xml, data_file).
print_log_module(module, print_flag=None)
Returns log module in XML format. Accepts only {dict}.
- Only works with one module at a time: otherwise iteration is needed.
- Module "value" field accepts str type.
- Use not_print_flag to avoid printing the XML (only populates variables).
print_module(module, print_flag=None)
Returns module in XML format. Accepts only {dict}.
- Only works with one module at a time: otherwise iteration is needed.
- Module "value" field accepts str type or [list] for datalists.
- Use print_flag to show modules' XML in STDOUT.
tentacle_xml(file, tentacle_ops, tentacle_path='', debug=0)
Sends file using tentacle protocol
- Only works with one file at time.
- file variable needs full file path.
- tentacle_opts should be a dict with tentacle options (address [password] [port]).
- tentacle_path allows to define a custom path for tentacle client in case is not in sys path).
- if debug is enabled, the data file will not be removed after being sent.
Returns 0 for OK and 1 for errors.
write_xml(xml, agent_name, data_dir='/var/spool/pandora/data_in/')
Creates a agent .data file in the specified data_dir folder.
Args:
- xml (str): XML string to be written in the file.
- agent_name (str): agent name for the xml and file name.
- data_dir (str): folder in which the file will be created.
translate_macros(macro_dic: dict, data: str)
Expects a macro dictionary key:value (macro_name:macro_value) and a string to replace macro. \n It will replace the macro_name for the macro_value in any string.
parse_csv_file(file, separator=';', count_parameters=None, debug=False) -> list:
Parse csv configuration. Reads configuration file and stores its data in an array.
Args:
- file (str): configuration csv file path. \n
- separator (str, optional): Separator for option and value. Defaults to ";".
- coun_parameters (int): min number of parameters each line shold have. Default None
- debug: print errors on lines
Returns:
- List: containing a list for each csv line.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Hashes for pandoraPlugintools-0.0.11.tar.gz
Algorithm | Hash digest | |
---|---|---|
SHA256 | 1e6d0fb0fe81bb907b918eb60f167dc3e784715298f38ab597d4e0f17e0c2e0a |
|
MD5 | 0425e32ff53a5c40f7c46ee83c06e9fc |
|
BLAKE2b-256 | 8c8b5d2247acce35ee56b608deafb1df1da0b2899c1cd1955cf6e32ca9fb5d9b |