Skip to content

Commit

Permalink
added documentation and test for user groups, fixed minor bug about d…
Browse files Browse the repository at this point in the history
…efault group misconfiguration in reportEmail
  • Loading branch information
massimocandela committed Oct 6, 2019
1 parent 47dfd47 commit 9f69f5d
Show file tree
Hide file tree
Showing 5 changed files with 20 additions and 8 deletions.
4 changes: 4 additions & 0 deletions docs/prefixes.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,12 +24,15 @@ Below the list of possible parameters. **Remember to prepend them with a `--` in

The prefix list is a file containing a series of blocks like the one below, one for each prefix to monitor.

>Tip: Only the attributes description, asn, and ignoreMorespecifics are mandatory.
```
165.254.255.0/24:
description: Rome peering
asn: 2914
ignoreMorespecifics: false
ignore: false,
group: aUserGroup
excludeMonitors:
- withdrawal-detection
path:
Expand Down Expand Up @@ -65,6 +68,7 @@ Below the complete list of attributes (the dot notation is used to represent yml
| path.matchDescription | The description that will be reported in the alert in case the regex test results in a match. | A string | No |
| path.maxLength | The maximum length allowed for an AS path. Longer paths will trigger an alert. | A number | No |
| path.minLength | The minimum length allowed for an AS path. Shorter paths will trigger an alert. | A number | No |
| group | The name of the group that will receive alerts about this monitored prefix. By default all alerts are sent to the "default" group. | A string | No |



Expand Down
14 changes: 10 additions & 4 deletions reports/reportEmail.js
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ export default class ReportEmail extends Report {

} else {

if (!this.params.notifiedEmails["default"]) {
if (!this.params.notifiedEmails["default"] || !this.params.notifiedEmails["default"].length) {
this.logger.log({
level: 'error',
message: "In notifiedEmails, for reportEmail, a group named 'default' is required for communications to the admin."
Expand Down Expand Up @@ -95,10 +95,13 @@ export default class ReportEmail extends Report {
.filter(item => !!item);

try {
return [...new Set(users)]
const emails = [...new Set(users)]
.map(user => {
return this.params.notifiedEmails[user];
});
})
.filter(item => !!item);

return (emails.length) ? emails : [this.params.notifiedEmails["default"]];
} catch (error) {
this.logger.log({
level: 'error',
Expand Down Expand Up @@ -197,7 +200,10 @@ export default class ReportEmail extends Report {

report = (channel, content) => {

if (Object.keys(this.templates).length > 0) {
if (Object.keys(this.templates).length > 0 &&
this.params.notifiedEmails &&
this.params.notifiedEmails["default"] &&
this.params.notifiedEmails["default"].length) {

const emailGroups = this.getEmails(content);

Expand Down
3 changes: 2 additions & 1 deletion reports/reportSlack.js
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,8 @@ export default class ReportSlack extends Report {
report = (message, content) => {
if (this.enabled){
let groups = content.data.map(i => i.matchedRule.group).filter(i => i != null);
groups = (groups.length) ? [...new Set(groups)] : Object.keys(this.params.hooks); // If there are no groups defined, send to all of them

groups = (groups.length) ? [...new Set(groups)] : Object.keys(this.params.hooks); // If there are no groups defined, send to all of them

for (let group of groups) {
if (this.params.hooks[group]) {
Expand Down
1 change: 1 addition & 0 deletions tests/prefixes.test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
description: description 2
asn: 15562
ignoreMorespecifics: false
group: groupName

192.147.168.0/24:
description: description 3
Expand Down
6 changes: 3 additions & 3 deletions tests/test.js
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,7 @@ describe("Tests", function() {
"description": "description 2",
"ignoreMorespecifics": false,
"prefix": "165.254.255.0/24",
"group": "default",
"group": "groupName",
"ignore": false,
"excludeMonitors" : [],
"includeMonitors": []
Expand Down Expand Up @@ -359,7 +359,7 @@ describe("Tests", function() {
extra: {},
matchedRule: {
prefix: "165.254.255.0/24",
group: "default",
group: "groupName",
description: "description 2",
asn: [15562],
ignoreMorespecifics: false
Expand Down Expand Up @@ -530,7 +530,7 @@ describe("Tests", function() {
extra: {},
matchedRule: {
prefix: '165.254.255.0/24',
group: 'default',
group: 'groupName',
description: 'description 2',
asn: [15562],
ignoreMorespecifics: false
Expand Down

0 comments on commit 9f69f5d

Please sign in to comment.