Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[snmp] configuration option to ignore non-increasing OIDs #1281

Merged
merged 2 commits into from
Jan 14, 2015
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 6 additions & 2 deletions checks.d/snmp.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

# project
from checks import AgentCheck
from config import _is_affirmative

# 3rd party
from pysnmp.entity.rfc3413.oneliner import cmdgen
Expand Down Expand Up @@ -41,18 +42,21 @@ def __init__(self, name, init_config, agentConfig, instances=None):

# Load Custom MIB directory
mibs_path = None
ignore_nonincreasing_oid = False
if init_config is not None:
mibs_path = init_config.get("mibs_folder")
SnmpCheck.create_command_generator(mibs_path)
ignore_nonincreasing_oid = _is_affirmative(init_config.get("ignore_nonincreasing_oid", False))
SnmpCheck.create_command_generator(mibs_path, ignore_nonincreasing_oid)

@classmethod
def create_command_generator(cls, mibs_path=None):
def create_command_generator(cls, mibs_path, ignore_nonincreasing_oid):
'''
Create a command generator to perform all the snmp query.
If mibs_path is not None, load the mibs present in the custom mibs
folder. (Need to be in pysnmp format)
'''
cls.cmd_generator = cmdgen.CommandGenerator()
cls.cmd_generator.ignoreNonIncreasingOid = ignore_nonincreasing_oid
if mibs_path is not None:
mib_builder = cls.cmd_generator.snmpEngine.msgAndPduDsp.\
mibInstrumController.mibBuilder
Expand Down
1 change: 1 addition & 0 deletions conf.d/snmp.yaml.example
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
init_config:
# #You can specify an additional folder for your custom mib files (python format)
# mibs_folder: /path/to/your/mibs/folder
# ignore_nonincreasing_oid: False

instances:

Expand Down
9 changes: 9 additions & 0 deletions tests/test_snmp.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,15 @@ def testInit(self):
custom_folder_represented = True
break
self.assertTrue(custom_folder_represented)
self.assertFalse(self.check.cmd_generator.ignoreNonIncreasingOid)

self.config = {
"init_config": {
"ignore_nonincreasing_oid": True
}
}
self.check = load_check('snmp', self.config, self.agentConfig)
self.assertTrue(self.check.cmd_generator.ignoreNonIncreasingOid)

def test_scalar_SNMPCheck(self):
self.config = {
Expand Down