Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[OpsGenie] Invite User Command #24586

Merged
merged 17 commits into from Feb 14, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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