-
Notifications
You must be signed in to change notification settings - Fork 39
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
Collect Juniper dom threshold values #2513
base: master
Are you sure you want to change the base?
Changes from 20 commits
22aa26d
2324494
e2e869b
ebc385d
2d6f307
b4f2cb8
867376e
ed62f06
fd078b6
9c8a55f
5eba3e0
d21aeb9
11a5613
ebcec4f
7a93cea
f6088cd
f768bdf
2a2ce7e
1ec98ce
a58dd65
0d5f2b6
4fd5cf5
ab3d427
a9a6080
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2331,6 +2331,13 @@ class Sensor(models.Model): | |
(ALERT_TYPE_WARNING, 'An orange warning'), | ||
) | ||
|
||
THRESHOLD_TYPE_HIGH = 1 | ||
THRESHOLD_TYPE_LOW = 2 | ||
THRESHOLD_TYPE_CHOICES = ( | ||
(THRESHOLD_TYPE_HIGH, 'Threshold for high values'), | ||
(THRESHOLD_TYPE_LOW, 'Threshold for low values'), | ||
) | ||
|
||
id = models.AutoField(db_column='sensorid', primary_key=True) | ||
netbox = models.ForeignKey(Netbox, on_delete=models.CASCADE, db_column='netboxid') | ||
interface = models.ForeignKey( | ||
|
@@ -2365,6 +2372,13 @@ class Sensor(models.Model): | |
alert_type = models.IntegerField( | ||
db_column='alert_type', choices=ALERT_TYPE_CHOICES, null=True | ||
) | ||
threshold_type = models.IntegerField( | ||
db_column='threshold_type', choices=THRESHOLD_TYPE_CHOICES, null=True | ||
) | ||
threshold_alert_type = models.IntegerField( | ||
db_column='threshold_alert_type', choices=ALERT_TYPE_CHOICES, null=True | ||
) | ||
threshold_for_oid = VarcharField(db_column='threshold_for_oid', null=True) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This would make sense to be a ForeignKey to the Sensor object this is a threshold for, but it didnt seem very easy to do. The values for the sensor object that is to be created are set after discovery, but before any objects are actually made, so refering to a sensor object that doesnt exist yet seems difficult. But pairing this |
||
|
||
class Meta(object): | ||
db_table = 'sensor' | ||
|
@@ -2484,6 +2498,29 @@ def get_display_configuration(self): | |
} | ||
return {} | ||
|
||
@property | ||
def threshold_for(self): | ||
"""Returns the sensor this is a threshold for. | ||
Returns None if no such sensor exists. | ||
""" | ||
if not self.threshold_for_oid: | ||
return None | ||
try: | ||
return self.__class__.objects.get( | ||
netbox=self.netbox, oid=self.threshold_for_oid, mib=self.mib | ||
) | ||
except self.DoesNotExist: | ||
_logger.error("Could not find sensor with oid %s", self.threshold_for_oid) | ||
return None | ||
|
||
@property | ||
def thresholds(self): | ||
"""Returns list of all threshold-sensors for this sensor""" | ||
thresholds = self.__class__.objects.filter( | ||
netbox=self.netbox, threshold_for_oid=self.oid, mib=self.mib | ||
) | ||
return list(thresholds) | ||
|
||
|
||
class PowerSupplyOrFan(models.Model): | ||
STATE_UP = u'y' | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
ALTER TABLE sensor | ||
ADD threshold_type INT, | ||
ADD threshold_alert_type INT, | ||
ADD threshold_for_oid VARCHAR | ||
; |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
from unittest import TestCase | ||
from mock import patch, Mock | ||
|
||
from twisted.internet import defer | ||
from twisted.internet.defer import succeed | ||
|
||
from nav.mibs.juniper_dom_mib import JuniperDomMib, SENSOR_COLUMNS, THRESHOLD_COLUMNS | ||
|
||
|
||
class TestJuniperDomMIB(TestCase): | ||
def setUp(self): | ||
pass | ||
|
||
def tearDown(self): | ||
pass | ||
|
||
def test_handle_sensor_column_returns_correct_amount_of_sensor_dicts(self): | ||
rows_for_column = {"0": "interface 0", "1": "interface 1"} | ||
|
||
with patch( | ||
'nav.mibs.juniper_dom_mib.JuniperDomMib.retrieve_column' | ||
) as retrieve: | ||
retrieve.return_value = succeed(rows_for_column) | ||
mib = JuniperDomMib(Mock()) | ||
column = "jnxDomCurrentRxLaserPower" | ||
deferred_result = mib.handle_sensor_column(column, SENSOR_COLUMNS[column]) | ||
result = deferred_result.result | ||
self.assertEqual(len(result), len(rows_for_column)) | ||
|
||
def test_handle_threshold_column_returns_correct_amount_of_sensor_dicts(self): | ||
rows_for_column = {"0": "interface 0", "1": "interface 1"} | ||
|
||
with patch( | ||
'nav.mibs.juniper_dom_mib.JuniperDomMib.retrieve_column' | ||
) as retrieve: | ||
retrieve.return_value = succeed(rows_for_column) | ||
mib = JuniperDomMib(Mock()) | ||
threshold_column = "jnxDomCurrentRxLaserPowerHighAlarmThreshold" | ||
sensor_column = "jnxDomCurrentRxLaserPower" | ||
deferred_result = mib.handle_threshold_column( | ||
threshold_column, | ||
THRESHOLD_COLUMNS[sensor_column][threshold_column], | ||
sensor_column, | ||
SENSOR_COLUMNS[sensor_column], | ||
) | ||
result = deferred_result.result | ||
self.assertEqual(len(result), len(rows_for_column), result) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Reuses pre-existing alert types. Figured this could give some consistency, as the already existing "Warning" and "Alert" match quite well with the "Warning" and "Alarm" naming scheme from the juniper thresholds.