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

Easyvista to py3 #22705

Merged
merged 9 commits into from Dec 6, 2022
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
138 changes: 138 additions & 0 deletions Packs/EasyVista/Integrations/EasyVista/EasyVista.py
@@ -0,0 +1,138 @@
import demistomock as demisto # noqa: F401
from CommonServerPython import * # noqa: F401

''' IMPORTS '''
import os
import urllib3
import requests

if not demisto.params()['proxy']:
del os.environ['HTTP_PROXY']
del os.environ['HTTPS_PROXY']
del os.environ['http_proxy']
del os.environ['https_proxy']

# Disable insecure warnings
urllib3.disable_warnings()

''' GLOBAL VARS '''
ACCOUNT = demisto.params()['account']
USERNAME = demisto.params()['credentials']['identifier']
PASSWORD = demisto.params()['credentials']['password']
SERVER = demisto.params()['server'][:-1] if demisto.params()['server'].endswith('/') else demisto.params()['server']
BASE_URL = f'{SERVER}/api/v1/{ACCOUNT}/'
USE_SSL = not demisto.params().get('insecure', False)

''' HELPER FUNCTIONS '''


def http_request(method, url_suffix):
demisto.debug(f'running request with url={BASE_URL}{url_suffix}')
try:
res = requests.request(
method,
BASE_URL + url_suffix,
verify=USE_SSL,
auth=requests.auth.HTTPBasicAuth(USERNAME, PASSWORD)
)
if res.status_code != 200:
raise Exception(f'Your request failed with the following error: {str(res.content)}{str(res.status_code)}')
except Exception as e:
demisto.debug(e)
raise
return res.json()


def dict_to_str(obj):
"""
Input - dictionary :
{
key1_keya: "valuea",
key1_keyb: "valueb",
HREF: "http://link"
}

Output - string:
Key1Keya: Valuea
Key1Keyb: Valueb
"""
string_result = ''
context_result = {}
for key, value in obj.items():
if key != 'HREF':
string_result = f'{string_result}{underscoreToCamelCase(key)}:{value}<br>'
context_result[underscoreToCamelCase(key)] = value
return string_result, context_result


''' FUNCTIONS '''


def search_command():
request = demisto.args().get('request')
if request:
response = search(request=request)
else:
asset = demisto.args().get('asset')
attribute = demisto.args().get('attribute')
value = demisto.args().get('value')
if asset and attribute and value:
response = search(asset, attribute, value)
else:
return 'Not enough arguments given'
records = []
context = []
for record in response:
string_record: dict = {}
context_record = {}
for header in record:
current_context = {}
if isinstance(record[header], dict):
current_string, current_context = dict_to_str(record[header])
if len(current_string) == 0:
string_record[header] = None
else:
string_record[header] = current_string
context_record[underscoreToCamelCase(header)] = current_context
records.append(string_record)
context.append(context_record)
if records:
title = 'EasyVista Search Results'
demisto.results({
'Type': entryTypes['note'],
'Contents': records,
'ContentsFormat': formats['json'],
'ReadableContentsFormat': formats['markdown'],
'HumanReadable': tableToMarkdown(title, records, headerTransform=underscoreToCamelCase, removeNull=True),
'EntryContext': {
'EasyVista.Records': context
}
})
else:
demisto.results('No records found')


def search(asset=None, attribute=None, value=None, request=None):
cmd_url = 'requests?search='
if request:
cmd_url += request
else:
cmd_url = f'{cmd_url}{asset}.{attribute}:"{value}"'
records = http_request('GET', cmd_url)['records']
return records


''' EXECUTION CODE '''
demisto.debug(f'command is {demisto.command()}')

try:
if demisto.command() == 'test-module':
http_request('GET', 'assets')
demisto.results('ok')

elif demisto.command() == 'easy-vista-search':
search_command()

except Exception as e:
demisto.debug(e)
raise e
139 changes: 139 additions & 0 deletions Packs/EasyVista/Integrations/EasyVista/EasyVista.yml
@@ -0,0 +1,139 @@
commonfields:
id: EasyVista
version: -1
name: EasyVista
display: EasyVista
category: IT Services
description: EasyVista Service Manager manages the entire process of designing, managing and delivering IT services.
configuration:
- display: Server URL (e.g. https://your_company.easyvista.com)
name: server
defaultvalue: ""
type: 0
required: true
- display: Account
name: account
defaultvalue: ""
type: 0
required: true
- display: Credentials
name: credentials
defaultvalue: ""
type: 9
required: false
- display: Trust any certificate (not secure)
name: insecure
type: 8
required: false
- display: Use system proxy settings
name: proxy
type: 8
required: false
script:
script: ''
type: python
subtype: python3
commands:
- name: easy-vista-search
arguments:
- name: asset
description: Asset to search, e.g. requestor (This argument is mandatory if the "request" argument is not given)
- name: attribute
description: Attribute to search, e.g. last_name (This argument is mandatory if the "request" argument is not given)
- name: value
description: Value to search, e.g. "Morley, Gaby" (This argument is mandatory if the "request" argument is not given)
- name: request
description: Integrated request of assets, attributes and values, e.g. requestor.last_name:"Morley, Gaby" (This argument replaces the other arguments given each one separately)
outputs:
- contextPath: EasyVista.Records.CatalogRequest.CatalogRequestPath
description: Catalog Request Path
type: string
- contextPath: EasyVista.Records.CatalogRequest.Code
description: Catalog Request Code
type: string
- contextPath: EasyVista.Records.CatalogRequest.SdCatalogId
description: SD Catalog ID
type: string
- contextPath: EasyVista.Records.CatalogRequest.TitleEn
description: Request Title
type: string
- contextPath: EasyVista.Records.Department.DepartmentCode
description: Department Code
type: string
- contextPath: EasyVista.Records.Department.DepartmentEn
description: Department Name
type: string
- contextPath: EasyVista.Records.Department.DepartmentId
description: Department ID
type: string
- contextPath: EasyVista.Records.Department.DepratmentLabel
description: Department Label
type: string
- contextPath: EasyVista.Records.Department.DepartmentPath
description: Department Path
type: string
- contextPath: EasyVista.Records.KnownProblem.KnownProblemPath
description: Known Problem Path
type: string
- contextPath: EasyVista.Records.KnownProblem.KnownProblemsId
description: Known Problems ID
type: string
- contextPath: EasyVista.Records.KnownProblem.KpNumber
description: Number of Known Problems
type: string
- contextPath: EasyVista.Records.KnownProblem.QuestionEn
description: Known problem question
type: string
- contextPath: EasyVista.Records.Location.City
description: City
type: string
- contextPath: EasyVista.Records.Location.LocationCode
description: Location Code
type: string
- contextPath: EasyVista.Records.Location.LocationEn
description: Location En
type: string
- contextPath: EasyVista.Records.Location.LocationId
description: Location ID
type: string
- contextPath: EasyVista.Records.Location.LocationPath
description: Location Path
type: string
- contextPath: EasyVista.Records.Recipient.BeginOfContract
description: Begin Of Contract Date
type: string
- contextPath: EasyVista.Records.Recipient.CellularNumber
description: Cellular number of recipient
type: string
- contextPath: EasyVista.Records.Recipient.DerpartmentPath
description: Department path of recipient
type: string
- contextPath: EasyVista.Records.Recipient.EMail
description: Email address of recipient
type: string
- contextPath: EasyVista.Records.Recipient.EmployeeId
description: Employee ID of recipient
type: string
- contextPath: EasyVista.Records.Recipient.LastName
description: Last name of recipient
type: string
- contextPath: EasyVista.Records.Recipient.LocationPath
description: Location of recipient
type: string
- contextPath: EasyVista.Records.Recipient.PhoneNumber
description: Phone number of recipient
type: string
- contextPath: EasyVista.Records.Status.StatusEn
description: Status of request
type: string
- contextPath: EasyVista.Records.Status.StatusGuid
description: Request GUID
type: string
- contextPath: EasyVista.Records.Status.StatusId
description: Request ID
type: string
description: This method allows a list of incidents / requests (service, change, investment) to be obtained.
dockerimage: demisto/python3:3.10.8.39276
tests:
- No tests
fromversion: 5.0.0
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.