Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

  1. We've scripted our check (in this example, Python).

  2. We've uploaded a script to GitHub.

  3. We’ve created our ASM check using a script in a GitHub repository.

  4. We've run our check in ASM and viewed the results.

  5. We've pulled the results for the API, including the custom JSON.

7. Appendix

Adding a Custom Python or NodeJS Module to ApicaNet for use with Scripted Checks

Adding a custom python or node.js module to your private Browser agent is very simple and should take less than 5 minutes. This guide assumes you have administrator access to your agent or have an operations team that will perform these steps for you.

  1. Determine the modules you need to install and log in to the private Browser agent.

  2. The worker runs apicanet in a chroot shell. This means you cannot simply run the following commands but must enter a chroot shell. To do this, run the following command:

    Code Block
    /opt/asm-browser-agent/chroot_shell.sh

     

  3. You should now be in a chroot shell. From here, you may interact with pip3 and npm (package managers for python 3.5 and nodejs).

  4. Install the necessary packages by running the following commands:

    Code Block
    # Node modules should be installed to the global scope.
    npm install -g <PACKAGE_NAME>
    
    # Python install command, ensure you use pip3, you should not touch the python2.7 install
    # The python2.7 install is used by ApicaNet itself.
    pip3 install <PACKAGE_NAME>

     

  5. Your packages are now installed and ready to use. If you wish, you can even test your script by opening a new shell instance and copying your script to /opt/asm-browser-agent/embedded/. You may then run your script in the chroot environment by using “node“ or “python3”. The script you placed in /opt/asm-browser-agent/embedded should be in the root folder of the chroot environment.

Tip

Tip: It’s a good idea to have 2 terminal windows open when testing; otherwise, it can be difficult to switch between the chroot and non-chroot windows in order to update and test your script. Alternatively, you can use scp (the secure copy command) to copy from your local computer to /opt/apicanet-worker/embedded/.

 Testing a Script on the Executing Agent Itself

It is possible to run a scripted check locally on the agent itself in order to ensure that all packages are installed in the correct location and that there are no syntax errors, etc. present. It is an excellent step to use when troubleshooting Python checks which are not running correctly.

  1. Copy the script onto /opt/asm-browser-agent/embedded on the agent itself

  2. cd ../ into /opt/asm-browser-agent

  3. run ./chroot_shell.sh (you can see this shell script if you run ls)

  4. The script you copied into /opt/asm-browser-agent/embedded should be in the root folder. Run ls to verify.

  5. You can run the script from the chroot shell using “node” or “python3”. Use the output to verify that the check is working without issue.