【问题标题】:Pagerduty grouping the incidents in one single incidentPagerduty 将事件分组到一个事件中
【发布时间】:2016-02-01 09:04:25
【问题描述】:

我使用 python 编写了一个端口扫描器,它将发送“非法端口打开”通知作为 pagerduty 的事件。集成工作正常,但有一个小问题困扰我。我无法为每个具有开放端口的主机发送唯一事件。假设我的脚本扫描了 2 个主机并发现发现非法端口并向 pagerduty 发送通知,如下所示:

 for serv in host.services:
                if serv.port not in safe_port:
                  print ('Illegal Port open :'+str(serv.port)+'/'+str(serv.protocol)+' '+str(serv.service)+', on host=> '+str(host))

                  notify_slack_forbidden_port(str(serv.port),str(serv.protocol),str(serv.service),str(host))
                  ######
                  notify_pagerduty_forbidden_port(str(serv.port),str(serv.protocol),str(serv.service),str(host))
                else:

notify_pagerduty_forbidden_port的函数定义如下:

def notify_pagerduty_forbidden_port(a,b,c,d):      ## Call this when a Forbidden port has been open up 
    headers = {
        'Authorization': 'Token token={0}'.format(API_ACCESS_KEY),
        'Content-type': 'application/json',
    }
    payload = json.dumps({
      "service_key": API_ACCESS_KEY,
      "incident_key": "illegal/port",
      "event_type": "trigger",
      "description": "A Illegle port was found open"+str(a)+"/ "+str(b)+" service "+str(c)+" on "+str(d)+" Found in "+str(box_name),
    })
    print "Sending to Pagerduty",payload
    r = requests.post(
                    'https://events.pagerduty.com/generic/2010-04-15/create_event.json',
                    headers=headers,
                    data=payload,
    )
    print "Done!"

我的问题是,当它被发送到 Pagerduty 时,它被视为一个事件而不是不同的事件:

我期望对于每个主机中的每个开放端口,都会生成不同的事件。

【问题讨论】:

    标签: python port-scanning


    【解决方案1】:

    docs 中描述了此行为:

    incident_key - Identifies the incident to which this trigger event should be applied. If there's no open (i.e. unresolved) incident with this key, a new one will be created. If there's already an open incident with a matching key, this event will be appended to that incident's log. The event key provides an easy way to "de-dup" problem reports.

    因此,如果您每次插入新问题时使用另一个 incident_key,您将获得一个新问题 ID。

    【讨论】:

    • 哦.. 谢谢,我想我应该从 pagerduty 通知程序中删除这个 "incident_key": "illegal/port",
    • 如果你想要一个独特的事件,我会在那里随机输入一个uuid
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-03-11
    • 2020-07-11
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多