SNMP Booster Developer Reference

SNMP Booster root class

This module contains the SnmpBoosterArbiter class which is the part of SNMP Booster loaded in the Arbiter

class module.snmpbooster.SnmpBooster(mod_conf)[source]

Bases: BaseModule

SNMP Poller module class Improve SNMP checks

init()[source]

Called by poller to say ‘let’s prepare yourself guy’

SNMP Booster classes

This module contains the SnmpBoosterArbiter class which is the part of SNMP Booster loaded in the Arbiter

class module.snmpbooster_arbiter.SnmpBoosterArbiter(mod_conf)[source]

Bases: module.snmpbooster.SnmpBooster

SNMP Poller module class Improve SNMP checks

hook_late_configuration(arb)[source]

Read config and fill database

This module contains the SnmpBoosterScheduler class which is the part of SNMP Booster loaded in the Scheduler

class module.snmpbooster_scheduler.SnmpBoosterScheduler(mod_conf)[source]

Bases: module.snmpbooster.SnmpBooster

SNMP Poller module class Improve SNMP checks

static get_frequence(chk)[source]

return check_interval if state type is HARD else retry_interval if state type is SOFT

hook_get_new_actions(sche)[source]

Set if is a SNMP or Cache check

static set_true_check(check, real=False)[source]

Add -r option to the command line

This module contains the SnmpBoosterPoller class which is the part of SNMP Booster loaded in the Poller

class module.snmpbooster_poller.SnmpBoosterPoller(mod_conf)[source]

Bases: module.snmpbooster.SnmpBooster

SNMP Poller module class Improve SNMP checks

get_new_checks()[source]

Get new checks if less than nb_checks_max If no new checks got and no check in queue, sleep for 1 sec REF: doc/shinken-action-queues.png (3)

launch_new_checks()[source]

Launch checks that are in status REF: doc/shinken-action-queues.png (4)

manage_finished_checks()[source]

This function handles finished check It gets output and exit_code and Add check to the return queue

save_results()[source]

Save results to database

work(master_slave_queue, returns_queue, control_queue)[source]

Main loop of SNMP Booster

SNMP Booster libs

This module contains two functions: * check_cache: Get data from cache * check_snmp: Get data from SNMP request

module.libs.checks.check_cache(check, arguments, db_client)[source]

Get data from database

module.libs.checks.check_snmp(check, arguments, db_client, task_queue, result_queue)[source]

Prepare snmp requests

This module contains database/cache abstraction class

class module.libs.dbclient.DBClient(db_host, db_port, db_name)[source]

Bases: object

Class used to abstract the use of the database/cache

connect()[source]

This function inits the connection to the database

disconnect()[source]

This function kills the connection to the database

get_service(host, service)[source]

This function gets one service from the database Return :query_result: dict

get_services(host, check_interval)[source]

This function Gets all services with the same host and check_interval Return :query_result: list of dicts

static handle_error(result, context='')[source]

This function handles mongodb errors

update_service(host, service, data)[source]

This function updates/inserts a service It used by arbiter in hook_late_configuration to put the configuration in the database Return * query_result: None * error: bool

update_service_init(host, service, data)[source]
update_service_instance(host, instance_name, instance)[source]

This function update a instance from SNMP mapping requests Return * query_result: None * error: bool

This module contains a set of functions to format the plugin output which is shown on the UI

module.libs.output.format_output(service, ds_name)[source]

Format value for derive type

module.libs.output.get_output(service)[source]

Prepare service output

module.libs.output.prepare_format(value, ds_data)[source]

Prepare a dict to put in string formatting

This module contains a function to retrieve output and compute trigger

module.libs.result.set_output_and_status(check_result)[source]

get output, compute exit_code an return it

This module contains a class to create a Thread which make SNMP requests and handle answers with callbacks

class module.libs.snmpworker.SNMPWorker(mapping_queue, max_prepared_tasks)[source]

Bases: threading.Thread

Thread which execute all SNMP tasks/requests

append_task_to_dispatcher(snmp_task)[source]
run()[source]

Process SNMP tasks SNMP task is a dict: - For a bulk request

{"authData": cmdgen.CommunityData('public')
 "transportTarget": cmdgen.UdpTransportTarget((transportTarget, 161))
 "nonRepeaters": 0
 "maxRepetitions": 64
 "varNames": ['1.3.6.1.2.1.2.2.1.2.0', '...']
 "cbInfo:: (cbFun, (arg1, arg2, ...))
 }
  • For a next request

    {"authData": cmdgen.CommunityData('public')
     "transportTarget": cmdgen.UdpTransportTarget((transportTarget, 161))
     "varNames": ['1.3.6.1.2.1.2.2.1.2.0', '...']
     "cbInfo:: (cbFun, (arg1, arg2, ...))
    }
    
  • For a get request

    {"authData": cmdgen.CommunityData('public)
     "transportTarget": cmdgen.UdpTransportTarget((transportTarget, 161))
     "varNames": ['1.3.6.1.2.1.2.2.1.2.0', '...']
     "cbInfo:: (cbFun, (arg1, arg2, ...))
    }
    
stop_worker()[source]

Stop SNMP worker thread

module.libs.snmpworker.callback_get(send_request_handle, error_indication, error_status, error_index, var_binds, cb_ctx)[source]

Callback function for GET SNMP requests

module.libs.snmpworker.callback_mapping_bulk(send_request_handle, error_indication, error_status, error_index, var_binds, cb_ctx)[source]

Callback function for BULK SNMP requests

module.libs.snmpworker.callback_mapping_next(send_request_handle, error_indication, error_status, error_index, var_binds, cb_ctx)[source]

Callback function for GENEXT SNMP requests

module.libs.snmpworker.handle_snmp_error(error_indication, cb_ctx, request_type)[source]

Handle SNMP errors

This module contains the function which compute triggers and return the exit code of a service

module.libs.trigger.get_trigger_result(service)[source]

Get return code from trigger calculator return error_message, exit_code :error_message: is None if there no error :exit_code: 0, 1, 2 or 3

Usefull functions used everywhere in snmp booster

module.libs.utils.calculation(value, ds_calc)[source]

Get result from calc

>>> calculation(1, [2, "add"])
3.0
module.libs.utils.compute_value(result)[source]

Get a computed value from raw_value, ds_type and calculation result argument must have this form

{'value_last': u'0',
 'calc': None,
 'check_time': 1410456115.376102,
 'key': {'host': u'myhost1',
         'ds_names': [u'ifOutErrors'],
         'service': u'if.lo',
         'oid_type': 'ds_oid'},
 'check_time_last': 1410456100.722268,
 'value_last_computed': u'0',
 'type': u'TEXT',
 'value': Counter32(0),
}
>>> data = {}
>>> data['value_last'] = u'0'
>>> data['calc'] = None
>>> data['check_time'] = 1410456115.376102
>>> data['key'] = {}
>>> data['key']['host'] = u'myhost1'
>>> data['key']['ds_names'] = [u'ifOutErrors']
>>> data['key']['service'] = u'if.lo'
>>> data['key']['oid_type'] = 'ds_oid'
>>> data['check_time_last'] = 1410456100.722268
>>> data['value_last_computed'] = u'Text collected from SNMP'
>>> data['type'] = u'TEXT'
>>> data['value'] = "Text collected from SNMP"
>>> compute_value(data)
'Text collected from SNMP'
module.libs.utils.derive(value, value_last, check_time, check_time_last, limit=4294967295)[source]

Get a derive

>>> derive(20, 10, 1412776670, 1412776660)
1.0
>>> derive(15, 4294967290, 1412776670, 1412776660)
2.0
>>> derive(20, 2**64 - 11, 1412776670, 1412776660, 2**64 - 1)
3.0
module.libs.utils.dict_serialize(serv, mac_resol, datasource)[source]

Get serv, datasource And return the service serialized

module.libs.utils.flatten_dict(tree_dict)[source]

Convert unlimited tree dictionnary to a flat dictionnary

>>> flatten_dict({'a': 1, 'b': {'c': {'d': 2, 'e': 4}}})
{'a': 1, 'b.c.d': 2, 'b.c.e': 4}
>>> flatten_dict("bad_input")
module.libs.utils.format_counter64_value(result)[source]

Format value for counter64 type

module.libs.utils.format_counter_value(result, limit=4294967295)[source]

Format value for counter type

module.libs.utils.format_derive64_value(result)[source]

Format value for derive64 type

module.libs.utils.format_derive_value(result, limit=4294967295)[source]

Format value for derive type

module.libs.utils.format_gauge_value(result)[source]

Format value for gauge type

module.libs.utils.format_text_value(result)[source]

Format value for text type

module.libs.utils.merge_dicts(old_dict, new_dict)[source]

Convert unlimited tree dictionnary to a flat dictionnary

>>> flatten_dict({'a': 1, 'b': {'c': {'d': 2, 'e': 4}}})
{'a': 1, 'b.c.d': 2, 'b.c.e': 4}
>>> flatten_dict("bad_input")
module.libs.utils.parse_args(cmd_args)[source]

Parse service command line and return a dict

module.libs.utils.rpn_calculator(rpn_list)[source]

Reverse Polish notation calculator

>>> rpn_calculator([4, 5, "add"])
9.0
>>> rpn_calculator([1, 2, "eq"])
False
>>> rpn_calculator([3, 2, "gt", 1, 1, "eq", "and_"])
True