mirror of
				https://github.com/nttgin/BGPalerter.git
				synced 2024-05-19 06:50:08 +00:00 
			
		
		
		
	introduced support for groups in Slack reporting - not back compatible
This commit is contained in:
		@@ -66,7 +66,8 @@ reports:
 | 
				
			|||||||
#      - newprefix
 | 
					#      - newprefix
 | 
				
			||||||
#      - visibility
 | 
					#      - visibility
 | 
				
			||||||
#    params:
 | 
					#    params:
 | 
				
			||||||
#      hookUrl: _YOUR_SLACK_WEBHOOK_URL_
 | 
					#      hooks:
 | 
				
			||||||
 | 
					#        default: _YOUR_SLACK_WEBHOOK_URL_
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
checkStaleNotificationsSeconds: 60
 | 
					checkStaleNotificationsSeconds: 60
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -76,7 +76,7 @@ export default class InputYml extends Input {
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
                        return Object.assign({
 | 
					                        return Object.assign({
 | 
				
			||||||
                            prefix: i,
 | 
					                            prefix: i,
 | 
				
			||||||
                            user: 'default'
 | 
					                            group: 'default'
 | 
				
			||||||
                        }, monitoredPrefixesFile[i])
 | 
					                        }, monitoredPrefixesFile[i])
 | 
				
			||||||
                    })
 | 
					                    })
 | 
				
			||||||
                    .filter(i => i !== null);
 | 
					                    .filter(i => i !== null);
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -1,6 +1,6 @@
 | 
				
			|||||||
{
 | 
					{
 | 
				
			||||||
  "name": "bgpalerter",
 | 
					  "name": "bgpalerter",
 | 
				
			||||||
  "version": "19.9.15.3",
 | 
					  "version": "19.9.17.3",
 | 
				
			||||||
  "description": "",
 | 
					  "description": "",
 | 
				
			||||||
  "main": "index.js",
 | 
					  "main": "index.js",
 | 
				
			||||||
  "bin": "index.js",
 | 
					  "bin": "index.js",
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -70,8 +70,8 @@ export default class ReportEmail extends Report {
 | 
				
			|||||||
    getEmails = (content) => {
 | 
					    getEmails = (content) => {
 | 
				
			||||||
        const users = content.data
 | 
					        const users = content.data
 | 
				
			||||||
            .map(item => {
 | 
					            .map(item => {
 | 
				
			||||||
                if (item.matchedRule && item.matchedRule.user){
 | 
					                if (item.matchedRule && item.matchedRule.group){
 | 
				
			||||||
                    return item.matchedRule.user;
 | 
					                    return item.matchedRule.group;
 | 
				
			||||||
                } else {
 | 
					                } else {
 | 
				
			||||||
                    return false;
 | 
					                    return false;
 | 
				
			||||||
                }
 | 
					                }
 | 
				
			||||||
@@ -86,7 +86,7 @@ export default class ReportEmail extends Report {
 | 
				
			|||||||
        } catch (error) {
 | 
					        } catch (error) {
 | 
				
			||||||
            this.logger.log({
 | 
					            this.logger.log({
 | 
				
			||||||
                level: 'error',
 | 
					                level: 'error',
 | 
				
			||||||
                message: 'Not all users have an associated email address'
 | 
					                message: 'Not all groups have an associated email address'
 | 
				
			||||||
            });
 | 
					            });
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -37,12 +37,23 @@ export default class ReportSlack extends Report {
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
    constructor(channels, params, env) {
 | 
					    constructor(channels, params, env) {
 | 
				
			||||||
        super(channels, params, env);
 | 
					        super(channels, params, env);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        this.enabled = true;
 | 
				
			||||||
 | 
					        if (!this.params.hooks || !Object.keys(this.params.hooks).length){
 | 
				
			||||||
 | 
					            this.logger.log({
 | 
				
			||||||
 | 
					                level: 'error',
 | 
				
			||||||
 | 
					                message: "Slack reporting is not enabled: no group is defined"
 | 
				
			||||||
 | 
					            });
 | 
				
			||||||
 | 
					            this.enabled = false;
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    report = (message, content) => {
 | 
					    _sendSlackMessage = (url, content) => {
 | 
				
			||||||
 | 
					        console.log("sending to", url);
 | 
				
			||||||
        axios({
 | 
					        axios({
 | 
				
			||||||
            url: this.params.hookUrl,
 | 
					            url: url,
 | 
				
			||||||
            method: "POST",
 | 
					            method: "POST",
 | 
				
			||||||
            resposnseType: "json",
 | 
					            resposnseType: "json",
 | 
				
			||||||
            data: {
 | 
					            data: {
 | 
				
			||||||
@@ -55,7 +66,18 @@ export default class ReportSlack extends Report {
 | 
				
			|||||||
                    message: error
 | 
					                    message: error
 | 
				
			||||||
                });
 | 
					                });
 | 
				
			||||||
            })
 | 
					            })
 | 
				
			||||||
 | 
					    };
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    report = (message, content) => {
 | 
				
			||||||
 | 
					        if (this.enabled){
 | 
				
			||||||
 | 
					            const groups = content.data.map(i => i.matchedRule.group);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					            for (let group of groups) {
 | 
				
			||||||
 | 
					                if (this.params.hooks[group]) {
 | 
				
			||||||
 | 
					                    this._sendSlackMessage(this.params.hooks[group], content);
 | 
				
			||||||
 | 
					                }
 | 
				
			||||||
 | 
					            }
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
@@ -137,42 +137,42 @@ describe("Tests", function() {
 | 
				
			|||||||
                            "description": "description 1",
 | 
					                            "description": "description 1",
 | 
				
			||||||
                            "ignoreMorespecifics": false,
 | 
					                            "ignoreMorespecifics": false,
 | 
				
			||||||
                            "prefix": "165.254.225.0/24",
 | 
					                            "prefix": "165.254.225.0/24",
 | 
				
			||||||
                            "user": "default"
 | 
					                            "group": "default"
 | 
				
			||||||
                        },
 | 
					                        },
 | 
				
			||||||
                        {
 | 
					                        {
 | 
				
			||||||
                            "asn": [15562],
 | 
					                            "asn": [15562],
 | 
				
			||||||
                            "description": "description 2",
 | 
					                            "description": "description 2",
 | 
				
			||||||
                            "ignoreMorespecifics": false,
 | 
					                            "ignoreMorespecifics": false,
 | 
				
			||||||
                            "prefix": "165.254.255.0/24",
 | 
					                            "prefix": "165.254.255.0/24",
 | 
				
			||||||
                            "user": "default",
 | 
					                            "group": "default",
 | 
				
			||||||
                        },
 | 
					                        },
 | 
				
			||||||
                        {
 | 
					                        {
 | 
				
			||||||
                            "asn": [15562],
 | 
					                            "asn": [15562],
 | 
				
			||||||
                            "description": "description 3",
 | 
					                            "description": "description 3",
 | 
				
			||||||
                            "ignoreMorespecifics": true,
 | 
					                            "ignoreMorespecifics": true,
 | 
				
			||||||
                            "prefix": "192.147.168.0/24",
 | 
					                            "prefix": "192.147.168.0/24",
 | 
				
			||||||
                            "user": "default",
 | 
					                            "group": "default",
 | 
				
			||||||
                        },
 | 
					                        },
 | 
				
			||||||
                        {
 | 
					                        {
 | 
				
			||||||
                            "asn": [204092, 45],
 | 
					                            "asn": [204092, 45],
 | 
				
			||||||
                            "description": "alarig fix test",
 | 
					                            "description": "alarig fix test",
 | 
				
			||||||
                            "ignoreMorespecifics": false,
 | 
					                            "ignoreMorespecifics": false,
 | 
				
			||||||
                            "prefix": "2a00:5884::/32",
 | 
					                            "prefix": "2a00:5884::/32",
 | 
				
			||||||
                            "user": "default"
 | 
					                            "group": "default"
 | 
				
			||||||
                        },
 | 
					                        },
 | 
				
			||||||
                        {
 | 
					                        {
 | 
				
			||||||
                            "asn": [208585],
 | 
					                            "asn": [208585],
 | 
				
			||||||
                            "description": "alarig fix test 2",
 | 
					                            "description": "alarig fix test 2",
 | 
				
			||||||
                            "ignoreMorespecifics": false,
 | 
					                            "ignoreMorespecifics": false,
 | 
				
			||||||
                            "prefix": "2a0e:f40::/29",
 | 
					                            "prefix": "2a0e:f40::/29",
 | 
				
			||||||
                            "user": "default"
 | 
					                            "group": "default"
 | 
				
			||||||
                        },
 | 
					                        },
 | 
				
			||||||
                        {
 | 
					                        {
 | 
				
			||||||
                            "asn": [1234],
 | 
					                            "asn": [1234],
 | 
				
			||||||
                            "description": "ignore sub test",
 | 
					                            "description": "ignore sub test",
 | 
				
			||||||
                            "ignoreMorespecifics": true,
 | 
					                            "ignoreMorespecifics": true,
 | 
				
			||||||
                            "prefix": "2a0e:f40::/30",
 | 
					                            "prefix": "2a0e:f40::/30",
 | 
				
			||||||
                            "user": "default"
 | 
					                            "group": "default"
 | 
				
			||||||
                        }
 | 
					                        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
                    ]
 | 
					                    ]
 | 
				
			||||||
@@ -299,7 +299,7 @@ describe("Tests", function() {
 | 
				
			|||||||
                            extra: {},
 | 
					                            extra: {},
 | 
				
			||||||
                            matchedRule: {
 | 
					                            matchedRule: {
 | 
				
			||||||
                                prefix: "165.254.255.0/24",
 | 
					                                prefix: "165.254.255.0/24",
 | 
				
			||||||
                                user: "default",
 | 
					                                group: "default",
 | 
				
			||||||
                                description: "description 2",
 | 
					                                description: "description 2",
 | 
				
			||||||
                                asn: [15562],
 | 
					                                asn: [15562],
 | 
				
			||||||
                                ignoreMorespecifics: false
 | 
					                                ignoreMorespecifics: false
 | 
				
			||||||
@@ -325,7 +325,7 @@ describe("Tests", function() {
 | 
				
			|||||||
                            extra: {},
 | 
					                            extra: {},
 | 
				
			||||||
                            matchedRule:{
 | 
					                            matchedRule:{
 | 
				
			||||||
                                prefix:"2a00:5884::/32",
 | 
					                                prefix:"2a00:5884::/32",
 | 
				
			||||||
                                user:"default",
 | 
					                                group:"default",
 | 
				
			||||||
                                description:"alarig fix test",
 | 
					                                description:"alarig fix test",
 | 
				
			||||||
                                asn:[204092, 45],
 | 
					                                asn:[204092, 45],
 | 
				
			||||||
                                ignoreMorespecifics:false
 | 
					                                ignoreMorespecifics:false
 | 
				
			||||||
@@ -351,7 +351,7 @@ describe("Tests", function() {
 | 
				
			|||||||
                            extra: {},
 | 
					                            extra: {},
 | 
				
			||||||
                            matchedRule:{
 | 
					                            matchedRule:{
 | 
				
			||||||
                                prefix: "2a00:5884::/32",
 | 
					                                prefix: "2a00:5884::/32",
 | 
				
			||||||
                                user: "default",
 | 
					                                group: "default",
 | 
				
			||||||
                                description: "alarig fix test",
 | 
					                                description: "alarig fix test",
 | 
				
			||||||
                                asn:[204092, 45],
 | 
					                                asn:[204092, 45],
 | 
				
			||||||
                                ignoreMorespecifics: false
 | 
					                                ignoreMorespecifics: false
 | 
				
			||||||
@@ -415,7 +415,7 @@ describe("Tests", function() {
 | 
				
			|||||||
                                extra: {},
 | 
					                                extra: {},
 | 
				
			||||||
                                matchedRule: {
 | 
					                                matchedRule: {
 | 
				
			||||||
                                    prefix: '165.254.255.0/24',
 | 
					                                    prefix: '165.254.255.0/24',
 | 
				
			||||||
                                    user: 'default',
 | 
					                                    group: 'default',
 | 
				
			||||||
                                    description: 'description 2',
 | 
					                                    description: 'description 2',
 | 
				
			||||||
                                    asn: [15562],
 | 
					                                    asn: [15562],
 | 
				
			||||||
                                    ignoreMorespecifics: false
 | 
					                                    ignoreMorespecifics: false
 | 
				
			||||||
@@ -441,7 +441,7 @@ describe("Tests", function() {
 | 
				
			|||||||
                            extra: {},
 | 
					                            extra: {},
 | 
				
			||||||
                            matchedRule: {
 | 
					                            matchedRule: {
 | 
				
			||||||
                                prefix: '2a00:5884::/32',
 | 
					                                prefix: '2a00:5884::/32',
 | 
				
			||||||
                                user: 'default',
 | 
					                                group: 'default',
 | 
				
			||||||
                                description: 'alarig fix test',
 | 
					                                description: 'alarig fix test',
 | 
				
			||||||
                                asn: [ 204092, 45],
 | 
					                                asn: [ 204092, 45],
 | 
				
			||||||
                                ignoreMorespecifics: false
 | 
					                                ignoreMorespecifics: false
 | 
				
			||||||
 
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user