adds #66. EventLog Check: Set the number of event logs found before passing/failing
This commit is contained in:
parent
880d8258ce
commit
792421b0e2
|
@ -0,0 +1,18 @@
|
|||
# Generated by Django 3.1.7 on 2021-03-06 02:18
|
||||
|
||||
from django.db import migrations, models
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
|
||||
dependencies = [
|
||||
('checks', '0021_auto_20210212_1429'),
|
||||
]
|
||||
|
||||
operations = [
|
||||
migrations.AddField(
|
||||
model_name='check',
|
||||
name='number_of_events_b4_alert',
|
||||
field=models.PositiveIntegerField(blank=True, default=1, null=True),
|
||||
),
|
||||
]
|
|
@ -181,6 +181,9 @@ class Check(BaseAuditModel):
|
|||
max_length=255, choices=EVT_LOG_FAIL_WHEN_CHOICES, null=True, blank=True
|
||||
)
|
||||
search_last_days = models.PositiveIntegerField(null=True, blank=True)
|
||||
number_of_events_b4_alert = models.PositiveIntegerField(
|
||||
null=True, blank=True, default=1
|
||||
)
|
||||
|
||||
def __str__(self):
|
||||
if self.agent:
|
||||
|
@ -488,13 +491,13 @@ class Check(BaseAuditModel):
|
|||
log.append(i)
|
||||
|
||||
if self.fail_when == "contains":
|
||||
if log:
|
||||
if log and len(log) >= self.number_of_events_b4_alert:
|
||||
self.status = "failing"
|
||||
else:
|
||||
self.status = "passing"
|
||||
|
||||
elif self.fail_when == "not_contains":
|
||||
if log:
|
||||
if log and len(log) >= self.number_of_events_b4_alert:
|
||||
self.status = "passing"
|
||||
else:
|
||||
self.status = "failing"
|
||||
|
|
|
@ -1003,6 +1003,12 @@ class TestCheckTasks(TacticalTestCase):
|
|||
"source": "source",
|
||||
"message": "a test message",
|
||||
},
|
||||
{
|
||||
"eventType": "error",
|
||||
"eventID": 123,
|
||||
"source": "source",
|
||||
"message": "a test message",
|
||||
},
|
||||
],
|
||||
}
|
||||
|
||||
|
@ -1107,3 +1113,61 @@ class TestCheckTasks(TacticalTestCase):
|
|||
new_check = Check.objects.get(pk=eventlog.id)
|
||||
|
||||
self.assertEquals(new_check.status, "passing")
|
||||
|
||||
# test multiple events found and contains
|
||||
# this should pass since only two events are found
|
||||
eventlog.number_of_events_b4_alert = 3
|
||||
eventlog.event_id_is_wildcard = False
|
||||
eventlog.event_source = None
|
||||
eventlog.event_message = None
|
||||
eventlog.event_id = 123
|
||||
eventlog.event_type = "error"
|
||||
eventlog.fail_when = "contains"
|
||||
eventlog.save()
|
||||
|
||||
resp = self.client.patch(url, data, format="json")
|
||||
self.assertEqual(resp.status_code, 200)
|
||||
|
||||
new_check = Check.objects.get(pk=eventlog.id)
|
||||
|
||||
self.assertEquals(new_check.status, "passing")
|
||||
|
||||
# this should pass since there are two events returned
|
||||
eventlog.number_of_events_b4_alert = 2
|
||||
eventlog.save()
|
||||
|
||||
resp = self.client.patch(url, data, format="json")
|
||||
self.assertEqual(resp.status_code, 200)
|
||||
|
||||
new_check = Check.objects.get(pk=eventlog.id)
|
||||
|
||||
self.assertEquals(new_check.status, "failing")
|
||||
|
||||
# test not contains
|
||||
# this should fail since only two events are found
|
||||
eventlog.number_of_events_b4_alert = 3
|
||||
eventlog.event_id_is_wildcard = False
|
||||
eventlog.event_source = None
|
||||
eventlog.event_message = None
|
||||
eventlog.event_id = 123
|
||||
eventlog.event_type = "error"
|
||||
eventlog.fail_when = "not_contains"
|
||||
eventlog.save()
|
||||
|
||||
resp = self.client.patch(url, data, format="json")
|
||||
self.assertEqual(resp.status_code, 200)
|
||||
|
||||
new_check = Check.objects.get(pk=eventlog.id)
|
||||
|
||||
self.assertEquals(new_check.status, "failing")
|
||||
|
||||
# this should pass since there are two events returned
|
||||
eventlog.number_of_events_b4_alert = 2
|
||||
eventlog.save()
|
||||
|
||||
resp = self.client.patch(url, data, format="json")
|
||||
self.assertEqual(resp.status_code, 200)
|
||||
|
||||
new_check = Check.objects.get(pk=eventlog.id)
|
||||
|
||||
self.assertEquals(new_check.status, "passing")
|
|
@ -95,6 +95,15 @@
|
|||
label="Alert Severity"
|
||||
/>
|
||||
</q-card-section>
|
||||
<q-card-section>
|
||||
<q-input
|
||||
label="Number of events found before alert"
|
||||
dense
|
||||
outlined
|
||||
type="number"
|
||||
v-model.number="eventlogcheck.number_of_events_b4_alert"
|
||||
/>
|
||||
</q-card-section>
|
||||
<q-card-section>
|
||||
<q-select
|
||||
outlined
|
||||
|
@ -137,6 +146,7 @@ export default {
|
|||
fail_when: "contains",
|
||||
search_last_days: 1,
|
||||
fails_b4_alert: 1,
|
||||
number_of_events_b4_alert: 1,
|
||||
event_id_is_wildcard: false,
|
||||
alert_severity: "warning",
|
||||
},
|
||||
|
|
Loading…
Reference in New Issue