Skip to content

Commit

Permalink
Allow configuring of SNMP to ignore non-increasing OIDs. Fixes #1231.
Browse files Browse the repository at this point in the history
  • Loading branch information
sethrosenblum committed Dec 5, 2014
1 parent 03ed309 commit 3e4aabb
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 2 deletions.
7 changes: 5 additions & 2 deletions checks.d/snmp.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,18 +34,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 = 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

0 comments on commit 3e4aabb

Please sign in to comment.