...
Step | Screenshot |
---|---|
About Adding JSON Return ValuesWhen we simply added some values into the JSON, we could have added any sort of content that you want to include. In the previous case, we added these:
| |
Adding More ValuesA very powerful concept that Apica supports with Scripted Checks: Add more fields to add more values. Let’s capture the headers coming out of our response by creating another field and calling it ' Add | Anything that JSON supports is supported in this result format. So you can add lists, inner dictionaries, null values, integers, booleans, etc. to this JSON. |
Later, we will show you how to retrieve this information through the ASM API. So anything that you can get from your code, you can get through the ASM API as your check is run.
2. Uploading the Check to a Repository
When you have finished writing the check and testing locally, upload the check Test your check locally before uploading to a repository which has been is linked to ASM. See Manage Repository Profiles for instructions on linking a repository for use within ASM. A repository can be added directly via the check creation wizard, when editing the check via the Edit Check page, or within the “Manage > Repository Profiles” page on the top ASM navigation bar.
3. Uploading and Running the Check in ASM
When the script is complete and uploaded to your repository profile, you are ready to create a Scripted check in ASM in order to utilize the script.
Note |
---|
You MUST select either “+1 Stockholm, Sweden, [amazon] or a private agent with the correct software installed when selecting an agent location. See “Run Python Step 2” for more information. |
...
Step
...
Screenshot
...
Open ASM
Navigate to New Check+
...
If you have a private agent with the necessary software installed and are planning to run the script on that agent, it is possible to test the script locally on the agent before uploading to your repository. See https://apica-kb.atlassian.net/wiki/spaces/ASMDOCS/pages/2135393547/Scripted+Check#Testing-a-Script-on-the-Executing-Agent-Itself for more information.
2. Uploading the Check to a Repository
When you have finished writing the check and testing locally, upload the check to a repository which has been linked to ASM. See Manage Repository Profiles for instructions on linking a repository for use within ASM. A repository can be added directly via the check creation wizard, when editing the check via the Edit Check page, or within the “Manage > Repository Profiles” page on the top ASM navigation bar.
3. Uploading and Running the Check in ASM
When the script is complete and uploaded to your repository profile, you are ready to create a Scripted check in ASM in order to utilize the script.
Note |
---|
You MUST select either “+1 Stockholm, Sweden, [amazon] or a private agent with the correct software installed when selecting an agent location. See “Run Python Step 2” for more information. |
Step | Screenshot | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|
Open ASMNavigate to New Check+ | ||||||||||||
Add Script via Run Python.The Run Python Scripted Check type icon should be displayed. If you don't have this, you may need to get it unlocked. Please ask your sales team for access because this is a more advanced check, not available for customers by default. | ||||||||||||
Creating a Run Python Check, Step 1Enter "New Test Check." Add any description and relevant tags, and then click Next. | ||||||||||||
Run Python Step 2Configure this check
| Resource URL/Github URL: This answers the question, "Where do we find your script?" This could be an HTTP download link, or it can be to your GitHub repository. For this example, go to your repository and copy+paste the URL here, ending with the branch ( Enter the URL that this script resides at. In this example, it resides in a GitHub Repo at Resource Auth Type: This type of resource authorization will be needed, GitHub or HTTP. This example uses GitHub. But if you have your file on an HTTP server, you could use HTTP as the type. Resource Auth: Resource authorization is required. The authorization header allows you to download resources.
Resource Path: This is the path inside your repository to the scripts you want to run. Our example scripts are just in the base level repository, so enter Secondary Resource: If your script requires any sort of additional files, you can use this secondary resource to download another file. However, you can also start your script off by downloading the file directly: That way, you can use any sort of security you want to protect it. For example, you could have a secondary resource, like a certificate protected by OAuth: Your script could go through the whole OAuth process and then use the local file. In this example, the secondary resource will be blank because it is unnecessary. It is possible to reference subfolders from a base directory using the “Secondary Resource” field. For instance, if your use case requires a “/python/main.py” file and main.py depends on a module defined in /python/modules, you can specify /python, and the check runner will recognize the module because it is able to “search” the /python folder for secondary resources. For example, if “local_module_sample.py” depends on a subfolder in /python, you can specify the project like so: Script Runner: Python is pre-selected (as the only choice). Script Arguments: These will be provided if we enter them on the command lines. Enter
In the field you would define your arguments as below
or
| |||||||||||
Step 3 Interval, Thresholds & Monitor GroupsIn this example, we will be creating a manual check. Select an interval, if needed, and check the groups you want this check to be a part of. Click Next. | ||||||||||||
Confirm Your CheckA Confirmation Page will be displayed for you to either go Back to edit it or Create to continue. If you are satisfied, you click Create to create the check. | ||||||||||||
Check Created
Apica generally recommends these settings for testing because what can happen is too long with the default behaviors. If Max Attempts remains at three and the Attempt Pause for each attempt is 30 seconds, this means that your test check could wait up to 90 seconds if it's failing. And so these settings don't help when trying just to debug something; it's better to have the information that your check failed from the beginning. Click the Check Details button in the upper right as we're ready to run our check. | ||||||||||||
Check Details PageThe Check Details page has a section called "Status Last 24 Hours," and beneath that will be a "Run Check" icon. Click to run manually. | ||||||||||||
Check ResultsIn this example, we set the “Last Value” to the status code by assigning it to the variable “value” in the script. |
| |||||||||||
Drill downDrilling into these results, we see the Result value (ms) is 200 because, even though the typical value for a result is the number of milliseconds it took to respond, we specified in our JSON that the value would be the response status code, so the 200 is displayed in its place. The number of Attempts is shown as 1, and beneath the result, code is the JSON that we specified: |
| |||||||||||
Messaging via JSONFrom Returned Value Table View, note the message it says URL call return status code 200. But this is the message that we sent inside of our JSON. So message when you set it will be placed here. So you can record any data you like, and it will show up here. |
...
Step | Screenshot |
---|---|
Open ASMNavigate to Tools, API Select a check using the drop-down box | |
Select the Target check for the APIWe've selected the Test Demo check. Beneath that check selection is some example API calls to help you get started quickly. We've copied the Last Result call pasted it into Postman to run it. |
|
Postman Results of Standard API Check EndpointHere, via API, is the last value of your check run, 200. | 200 is the last status code of the URL. This is nice but is just a raw number without data or context, and there's no JSON used. This could be used just for a small script or something you can pull the last result of your check maybe test it for something. A better API endpoint is the Checks Generic Check ID Results API endpoint. |
Apica API for Generic ResultsThis API endpoint looks up the results for checks that present a result type of generic. 'Generic' checks mean that they have the expandable JSON result format we saw in Step 5 above. | Generic type Checks: Run Python scripts, Run Javascript, Run Java, and (when released) Run Azure Cloud, Run Lamda, etc. |
Postman Results of Generic API Check EndpointIn Postman, using this API endpoint:
Instead of the earlier (for comparison):
| The API documentation for Generic Check shows these capabilities:
This is a POST endpoint: Note the JSON results returned above. So you may need to use these in some other API call to lookup even more information. In this example, we're just going to use the most recent because that is the simplest and easiest to show. |
The Result ObjectNote the headers that returned and (not shown in the screen capture) the content size, the header count, etc. All of the information you recorded in your script comes through the API. | What you choose to do next with these metrics is all up to your needs.
|
...
Testing a Script on the Executing Agent Itself
If you are running a script from a private agent, It is possible to run a scripted check locally on the agent itself it locally in order to ensure that all packages are installed in the correct location and that there are no syntax errors, etc. are present. It is an excellent step to use when troubleshooting Python checks which are not running correctly.
...