Skip to content

Commit

Permalink
[OpsGenie] Invite User Command (#24586) (#24606)
Browse files Browse the repository at this point in the history
* demisto api integration name change

* Update .devcontainer.json name

* added a new command

* reverting some files

* removed a blank line

* modified readme

* opsgenie readme fix

* description fix

* release note fix

* documentation fixes

---------

Co-authored-by: Enes Özdemir <49711791+ennozdd@users.noreply.github.com>
Co-authored-by: ennozdd <ennozdd@users.noreply.github.com>
  • Loading branch information
3 people authored and melamedbn committed Feb 15, 2023
1 parent 17c1b19 commit ae2d78b
Show file tree
Hide file tree
Showing 8 changed files with 191 additions and 101 deletions.
23 changes: 21 additions & 2 deletions Packs/OpsGenie/Integrations/OpsGenieV3/OpsGenieV3.py
@@ -1,20 +1,21 @@
from requests import Response

import urllib3
import demistomock as demisto
from typing import Callable, Tuple
from CommonServerPython import * # noqa # pylint: disable=unused-wildcard-import
from CommonServerUserPython import * # noqa

# Disable insecure warnings
DEFAULT_POLL_INTERVAL = 5
requests.packages.urllib3.disable_warnings() # pylint: disable=no-member
urllib3.disable_warnings()

''' CONSTANTS '''
DEFAULT_POLL_TIMEOUT = 60
INTEGRATION_NAME = 'Opsgenie'
ALERTS_SUFFIX = "alerts"
REQUESTS_SUFFIX = "requests"
SCHEDULE_SUFFIX = "schedules"
USERS_SUFFIX = "users"
INCIDENTS_SUFFIX = "incidents"
ESCALATION_SUFFIX = "escalations"
TEAMS_SUFFIX = "teams"
Expand Down Expand Up @@ -303,6 +304,12 @@ def remove_tag_incident(self, args: dict):
params={"tags": args.get('tags')},
json_data=args)

def invite_user(self, args):
return self._http_request(method='POST',
url_suffix=f"/v2/{USERS_SUFFIX}",
json_data=args
)

def get_team(self, args: dict):
return self._http_request(method='GET',
url_suffix=f"/v2/{TEAMS_SUFFIX}/{args.get('team_id')}"
Expand Down Expand Up @@ -839,6 +846,17 @@ def get_request_command(client: Client, args: Dict[str, Any]) -> CommandResults:
)


def invite_user(client, args) -> CommandResults:
args['role'] = {'name': args.get('role')}
result = client.invite_user(args)
return CommandResults(
outputs_prefix="OpsGenie.Users",
outputs=result.get("data"),
readable_output=tableToMarkdown("OpsGenie Users", result.get("data")),
raw_response=result
)


def get_teams(client: Client, args: Dict[str, Any]) -> CommandResults:
result = client.get_team(args) if args.get("team_id") else client.list_teams()
return CommandResults(
Expand Down Expand Up @@ -989,6 +1007,7 @@ def main() -> None:

commands = {
'opsgenie-create-alert': create_alert,
'opsgenie-invite-user': invite_user,
'opsgenie-get-alerts': get_alerts,
'opsgenie-delete-alert': delete_alert,
'opsgenie-ack-alert': ack_alert,
Expand Down

0 comments on commit ae2d78b

Please sign in to comment.