diff --git a/docs/source/ruletypes.rst b/docs/source/ruletypes.rst index ff3763712..ba619fdea 100644 --- a/docs/source/ruletypes.rst +++ b/docs/source/ruletypes.rst @@ -2031,6 +2031,20 @@ Optional: ``servicenow_proxy``: By default ElastAlert will not use a network proxy to send notifications to ServiceNow. Set this option using ``hostname:port`` if you need to use a proxy. +``caller_id``: Used to log the ticket under another name than user making request. + +``impact``: Used to specify the impact of the incident created. + +``urgency``: Used to specify the urgency of the incident created. + +``u_originating_group``: The originating group the incident is for. + +``u_division``: The Division the incident is specified for. + +``contact_type``: The preferred contact method. + +``opened_by``: Specifies the user that opened it. + Debug ~~~~~ diff --git a/elastalert/alerts.py b/elastalert/alerts.py index f2f31853f..2b014ec45 100644 --- a/elastalert/alerts.py +++ b/elastalert/alerts.py @@ -1778,22 +1778,18 @@ def get_info(self): class ServiceNowAlerter(Alerter): """ Creates a ServiceNow alert """ required_options = set([ - 'username', - 'password', - 'servicenow_rest_url', + 'apikey', + 'servicedeskplus_rest_url', 'short_description', 'comments', 'assignment_group', 'category', - 'subcategory', - 'cmdb_ci', - 'caller_id' + 'subcategory' ]) def __init__(self, rule): super(ServiceNowAlerter, self).__init__(rule) - self.servicenow_rest_url = self.rule['servicenow_rest_url'] - self.servicenow_proxy = self.rule.get('servicenow_proxy', None) + self.servicedeskplus_rest_url = self.rule['servicedeskplus_rest_url'] +"?zapikey="+ self.rule['apikey'] def alert(self, matches): for match in matches: @@ -1805,7 +1801,6 @@ def alert(self, matches): "Content-Type": "application/json", "Accept": "application/json;charset=utf-8" } - proxies = {'https': self.servicenow_proxy} if self.servicenow_proxy else None payload = { "description": description, "short_description": self.rule['short_description'], @@ -1813,25 +1808,25 @@ def alert(self, matches): "assignment_group": self.rule['assignment_group'], "category": self.rule['category'], "subcategory": self.rule['subcategory'], - "cmdb_ci": self.rule['cmdb_ci'], - "caller_id": self.rule["caller_id"] + "impact": self.rule["impact"], + "urgency": self.rule["urgency"], + "priority": self.rule["impact"], + "u_division": self.rule["u_division"] } try: response = requests.post( - self.servicenow_rest_url, - auth=(self.rule['username'], self.rule['password']), + self.servicedeskplus_rest_url, headers=headers, data=json.dumps(payload, cls=DateTimeEncoder), - proxies=proxies ) response.raise_for_status() except RequestException as e: - raise EAException("Error posting to ServiceNow: %s" % e) - elastalert_logger.info("Alert sent to ServiceNow") + raise EAException("Error posting to ServiceDeskPlus: %s" % e) + elastalert_logger.info("Alert sent to ServiceDeskPlus") def get_info(self): - return {'type': 'ServiceNow', - 'self.servicenow_rest_url': self.servicenow_rest_url} + return {'type': 'ServiceDeskPlus', + 'self.servicedeskplus_rest_url': self.rule['servicedeskplus_rest_url']} class AlertaAlerter(Alerter): diff --git a/elastalert/loaders.py b/elastalert/loaders.py index 771194768..8e2298a6d 100644 --- a/elastalert/loaders.py +++ b/elastalert/loaders.py @@ -74,7 +74,7 @@ class RulesLoader(object): 'telegram': alerts.TelegramAlerter, 'googlechat': alerts.GoogleChatAlerter, 'gitter': alerts.GitterAlerter, - 'servicenow': alerts.ServiceNowAlerter, + 'servicedeskplus': alerts.ServiceNowAlerter, 'alerta': alerts.AlertaAlerter, 'post': alerts.HTTPPostAlerter, 'hivealerter': alerts.HiveAlerter diff --git a/elastalert/schema.yaml b/elastalert/schema.yaml index 1241315dc..675c6a03e 100644 --- a/elastalert/schema.yaml +++ b/elastalert/schema.yaml @@ -315,6 +315,14 @@ properties: properties: field: {type: string, minLength: 1} + ### ServiceNow + impact: {type: [string, integer]} + urgency: {type: [string, integer]} + u_originating_group: {type: string} + u_division: {type: string} + contact_type: {type: string} + opened_by: {type: string} + ### PagerDuty pagerduty_service_key: {type: string} pagerduty_client_name: {type: string}