How to use get_value_from_context method in toolium

Best Python code snippet using toolium_python

ArcannaFeedbackPostProcessingScript.py

Source:ArcannaFeedbackPostProcessingScript.py Github

copy

Full Screen

1import demistomock as demisto2from CommonServerPython import *3from CommonServerUserPython import *4ARCANNA_AUTO_CLOSED_TICKET_PLAYBOOK_PLACEHOLDER = "Arcanna decision:"5def get_value_from_context(key):6 return demisto.get(demisto.context(), key)7def send_arcanna_feedback(close_notes, close_reason, closing_user, event_id, job_id):8 ret = demisto.executeCommand("arcanna-send-event-feedback", {9 "job_id": job_id,10 "event_id": event_id,11 "label": close_reason,12 "username": closing_user,13 "closing_notes": close_notes14 })15 return ret16def extract_feedback_information():17 feedback_field = get_value_from_context(key="Arcanna.FeedbackField")18 if type(feedback_field) == list and len(feedback_field) > 0:19 feedback_field = feedback_field[0]20 if not feedback_field:21 raise Exception("Failed to get value for Arcanna closing field")22 # Get Values from incident23 feedback_field_value = demisto.incident().get(feedback_field, None)24 if not feedback_field_value:25 # if closing field value is Empty try to get it from Args as a fallback26 feedback_field_value = demisto.args().get(feedback_field, None)27 return feedback_field, feedback_field_value28def add_closing_user_information(closing_user, owner, survey_user):29 if not closing_user:30 if survey_user:31 closing_user = survey_user32 elif owner:33 closing_user = owner34 else:35 closing_user = "dbot"36 return closing_user37def run_arcanna_send_feedback():38 try:39 event_id = get_value_from_context(key="Arcanna.Event.event_id")40 job_id = get_value_from_context(key="Arcanna.Event.job_id")41 incident = demisto.incident()42 run_status = incident.get("runStatus")43 if run_status == "waiting":44 return_error("Trying to close and incident without completing task")45 incident_id = incident.get('id')46 if not event_id:47 demisto.debug("Trying to send feedback for an event which was not sent to Arcanna first.Skipping")48 return_results(f'Skipping event feedback with id={incident_id}')49 return50 args_closing_reason = demisto.args().get("closing_reason", None)51 if args_closing_reason:52 user = demisto.args().get("closing_user", None)53 notes = demisto.args().get("closing_notes", None)54 ret = send_arcanna_feedback(notes, args_closing_reason, user, event_id, job_id)55 return_results(ret)56 else:57 demisto.executeCommand("arcanna-get-feedback-field", {})58 feedback_field, feedback_field_value = extract_feedback_information()59 close_reason = incident.get('closeReason', None)60 close_notes = incident.get('closeNotes')61 owner = incident.get('owner', None)62 closing_user = incident.get('closingUserId', None)63 demisto.debug(f"Values supplied to command are{feedback_field} "64 f"close_reason={close_reason} owner={owner} closing_user={closing_user} "65 f"close_notes={close_notes}")66 # if feedback_field_value is not empty get that value, else use the default closeReason value67 if feedback_field_value:68 close_reason = feedback_field_value69 survey_user = get_value_from_context(key="Closure_Reason_Survey.Answers.name")70 # Arcanna-Generic-Playbook usage.Prevent sending Arcanna Feedback if no analyst reviewed the incident71 if str(close_notes).startswith(ARCANNA_AUTO_CLOSED_TICKET_PLAYBOOK_PLACEHOLDER):72 return_results(73 f'Skipping Sending Arcanna event feedback for incident_id={incident_id}.No Analyst Reviewed')74 return75 if not closing_user and not close_notes and not close_reason:76 return_results(77 f'Skipping Sending Arcanna event feedback for incident_id={incident_id}.No Analyst Reviewed')78 return79 if not close_reason:80 raise Exception(81 "Trying to use Arcanna post-processing script without providing value for the closing field")82 closing_user = add_closing_user_information(closing_user, owner, survey_user)83 ret = send_arcanna_feedback(close_notes, close_reason, closing_user, event_id, job_id)...

Full Screen

Full Screen

modified.py

Source:modified.py Github

copy

Full Screen

...16 dots_var = dots_var[-1]17 else:18 params = []19 if 'nullable' in params:20 value = get_value_from_context(context, dots_var, nullable=True)21 else:22 value = get_value_from_context(context, dots_var, nullable=False)23 if 'get' in key:24 delete_keys.append(key)25 if value:26 get_key = key.split('_')[1]27 get[get_key] = value28 elif value:29 kwargs[key] = value30 else:31 kwargs[key] = 'None'32 for key in delete_keys:33 del kwargs[key]34 return build_url(viewname, **kwargs, get=get)35@register.simple_tag(takes_context=True)36def cookie(context, cookie_name):37 request = context['request']38 result = request.COOKIES.get(cookie_name, '')39 return result40def get_value_from_context(context, dots_var, nullable=False):41 c_key = dots_var.split('.')[0]42 try:43 var = context[c_key]44 except KeyError:45 if nullable:46 return None47 raise KeyError('Template context does not exist key: {}'.format(c_key))48 splitted_var = dots_var.split('.')49 if len(splitted_var) > 0:50 attr = '.'.join(splitted_var[1:])51 try:52 value = getattr(var, attr)53 except Exception:54 if nullable:...

Full Screen

Full Screen

Automation Testing Tutorials

Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Run toolium automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful