openwisp-monitoring
openwisp-monitoring copied to clipboard
[feature] Implement SNMP check #297
Closes #297
Checks:
- [x] I have manually tested the proposed changes
- [x] I have written new test cases to avoid regressions (if necessary)
- [x] I have updated the documentation (e.g. README.rst)
Coverage increased (+0.03%) to 98.936% when pulling aaad59aa7c332662b8673285f541f59b6732612b on issues/297-snmp-check into abd916533af557fb9689d24b3954017dfcfb3435 on master.
Interface information of the device is not shown on in device status page. I think the culprit is the following code:
https://github.com/openwisp/openwisp-monitoring/blob/3d094acf63b8343d0d60a4d9e9ade2bccabcad16/openwisp_monitoring/device/base/models.py#L80-L82
@purhan please ensure that information about interfaces is displayed
@pandafy Thanks! I found out the problem in netengine and fixed it in this commit. It should be working now, we don't need to change anything here
During our testing we noticed that the CPU load chart is not laoded for AirOS, can you please fix this?
@nemesisdesign This was done in https://github.com/openwisp/netengine/pull/62/commits/5424532015231d8bd311e8282dca74506dc485ab
I need to increase coverage.
@nemesisdesign The coverage is reduced due to absence of test_auto_check_creation -> SNMP auto subtest (which I later added), So I tried various methods to set AUTO_SNMP = True in check/tests/test_models.py using @patch() / @patch_objects() /@override_settings() , They indeed set AUTO_SNMP to True but before calling post_save.connect() (checks/apps.py) AUTO_SNMP always False due to which check never created.
See below:
# check/tests/test_models.py
@patch('openwisp_monitoring.check.settings.AUTO_SNMP', True)
def test_auto_check_creation(self):
self.assertEqual(Check.objects.count(), 0)
d = self._create_device(organization=self._create_org())
print(app_settings.__dict__)
print(Check.objects.all())
# check is automatically created via django signal
self.assertEqual(Check.objects.count(), 3) # It should have Ping, Config Applied & SNMP
... ...
... ...
with self.subTest('Test AUTO_SNMP'):
c3 = Check.objects.filter(check_type=self._SNMP_DEVICEMONITORING).first()
self.assertEqual(c3.content_object, d)
self.assertEqual(self._SNMP_DEVICEMONITORING, c3.check_type)
print(f'Value of AUTO_SNMP = {app_settings.AUTO_SNMP}')
if app_settings.AUTO_SNMP:
...
...
print(app_settings.__dict__)
print(Check.objects.all())
# output
Value of AUTO_SNMP = False # Because of this snmp signal not called and check not created
... ... ... 'AUTO_PING': True, 'AUTO_CONFIG_CHECK': True, 'AUTO_SNMP': True, 'MANAGEMENT_IP_ONLY': False, 'PING_CHECK_CONFIG': {}}
<QuerySet [<Check: Ping (Device: default.test.device)>, <Check: Configuration Applied (Device: default.test.device)>]>
AssertionError: 2 != 3
----------------------------------------------------------------------
Ran 1 test in 0.092s
FAILED (failures=1)
Current possible solution :
- Set
AUTO_SNMPdirectly inopenwisp-monitoring/tests/openwisp2/settings.py - Made required changes in broken tests https://github.com/openwisp/openwisp-monitoring/pull/309/commits/aaad59aa7c332662b8673285f541f59b6732612b.
# settings.py
if TESTING:
...
...
# for testing AUTO_SNMP
OPENWISP_MONITORING_AUTO_SNMP = True