Troubleshooting

The Snippet Framework enables a user to quickly debug an issue through ad-hoc UIDebug or during a typical collection process which utilizes the File System. Below are some scenarios you may encounter and potential ways to address them.

De-Duplication Issues

During processing of the Snippet Framework, all steps are de-duplicated which prevents the same set of code from running multiple times when the results should be the same. Steps that do not modify references can be marked as mutable=False, which states references will not be modified. However if a step is incorrectly marked, issues may arise where data you expect to be present is not present from a modification. If this occurs, the fix would be to mark the step as mutable=True during registration. However if you cannot make this change, you can mark all steps as mutable. By making this change, the Snippet Framework will consume more memory but will alleviate the issue until the step can be correctly marked as mutable. To mark all steps as mutable, edit the snippet and find the call to snippet_framework and add force_mutable=True. After marking all steps as mutable, the following log message will appear during execution:

Setting all steps to mutable due to the following snippets: <List of snippet IDs>

Below is an example of the updated call to snippet_framework where we are forcing all steps to mutable:

snippet_framework(collections, custom_substitution, snippet_id, app=self, force_mutable=True)

Dynamic Single

Dynamic Single is a tool that allows for direct execution of a Dynamic Application for a specific device. This script must be ran on the Collector where the Dynamic Application runs for the particular device.

To execute Dynamic Single, the following command must be run:

sudo -u s-em7-core /opt/em7/backend/dynamic_single.py <did> <app_id>

There are additional environment variables that you can specify when running a command. These options enable additional functionality of the framework for more in-depth debugging options.

  • DEBUG: Enables debug output if this value is set to True. Default: False

  • SF_LOG_FULL_RESULT: Log the entire result after each step, instead of the first 1024 characters. Please take care when using this option as it can greatly increase log sizes. Default: False

  • SF_LOG_FULL_RC: The log message of a ResultContainer will contain all characters instead of the first 1024 characters. Please take care when using this option as it can greatly increase log sizes. Default: False

To execute Dynamic Single with options, the following command must be run:

sudo -u s-em7-core <ENV VARS> /opt/em7/backend/dynamic_single.py <did> <app_id>

sudo -u s-em7-core DEBUG=1 SF_LOG_FULL_RESULT=1 /opt/em7/backend/dynamic_single.py <did> <app_id>

Dynamic Single Permission Error

If the execution environments were created with an invalid user, you could see an error related to permissions at execution time. This could happen if debug mode was executed with the dynamic single option incorrectly.

To solve this error, set the permissions manually using the following commands.

chown -R s-em7-core:s-em7-core /opt/em7/envs/<env_guid>
chown s-em7-core:s-em7-core /var/log/em7/snippet_framework*.log

Looking up an Execution Environment GUID

The following steps show how to obtain the Execution Environment GUID:

  1. Navigate to the Dynamic Application page (System -> Manage -> Dynamic Applications)

  2. Click the wrench icon for the Dynamic Application that is experiencing an issue

  3. Find the drop-down labeled Execution Environment. This information will be used in a future step.

  4. Navigate to the ScienceLogic Libraries page (System -> Customize -> ScienceLogic Libraries)

  5. Click on Actions on the top-right of the page and select Execution Environments

  6. Search for the Execution Environment from step 3

    • The Env GUID will be used to forming the path to the Execution Environment

For example, if your Env GUID is 6148EE552E7AE6AFB9B13F206C997DC8, the path for interacting with Log Policies would be

/opt/em7/envs/6148EE552E7AE6AFB9B13F206C997DC8/bin/python

Framework Exceptions and Solutions

This section describes the most common exceptions found when debugging collection issues or developing new snippet arguments. The section below describes what each exception means, along with possible troubleshooting methods to resolve them.

Snippet Errors

You may encounter some other errors and exceptions while using the Snippet Framework like the ones mentioned below.

By modifying the User Editable area, if there are some mistakes in the source code you may see a Syntax Error. To solve the error you should review the syntax of your custom code. A good starting point is comparing your custom Snippet to what is provided in the Default Snippet.

../_images/SyntaxtError.png

Another common error can be the Import Error. If this is the case, you should review and fix your execution environment.

../_images/ImportError.png

Unhandled Framework Error

When an unhandled error occurs in the Snippet Framework, collect the following logs from the collector, and contact ScienceLogic Support:

  • /var/log/em7/snippet_framework.log

../_images/UnhandledFrameworkExceptions.png

Step Errors

When a step error occurs in the Snippet Framework, the logs can be viewed either in the Device Logs or by executing Dynamic Single and checking the output.