cancel
Showing results for 
Search instead for 
Did you mean: 
taras
Sisense Team Member
Sisense Team Member

Automating Plugin Management in Sisense: A Bash Script Solution

Introduction:

This solution is applicable for Sisense on Linux on-premise installations.

Managing plugins in Sisense, particularly in scenarios where multiple plugins need to be updated or reverted, can be a time-consuming task. However, by leveraging bash scripting, this process can be automated to save time and ensure consistency across plugins. In this article, we'll provide two bash scripts designed to update and revert changes to plugin configurations in Sisense - particularly changing the enabled/disabled state. These scripts are intended to be executed in the `/opt/sisense/storage/plugins` folder, where all plugins(add-ons) and their subfolders reside.

Prerequisites:

Before using the provided scripts, ensure you have the following:

1. Access to the Sisense server and permission to create, modify and execute files in /opt/sisense/storage/plugins (Sisense for Linux On-Prem installations).
2. Basic understanding of bash scripting.
3. Familiarity with JSON file structure.

Script Overview:

The provided scripts consist of two parts:

1. Search and Update Script: This script searches for `plugin.json` files within subfolders of the `/opt/sisense/storage/plugins` directory. It updates the `isEnabled` key to `false` if it's `true` and logs the corresponding folder names in a separate file.

 

#!/bin/bash

# Clean the file before writing to it
> updated_plugin_names.txt

# Function to search for plugin.json and update "isEnabled" value
search_and_update() {
    # Loop through subfolders
    for dir in */; do
        if [ -f "$dir/plugin.json" ]; then
            # Extract folder name
            folderName=$(jq -r '.folderName' "$dir/plugin.json")
            # Store name in separate file
            isEnabled=$(jq -r '.isEnabled' "$dir/plugin.json")
            if [ "$isEnabled" == "true" ]; then
                # Update "isEnabled" to false
                jq '.isEnabled = false' "$dir/plugin.json" > temp.json && mv temp.json "$dir/plugin.json"
                # Log name only for updated plugin.json
                echo "\"folderName\": \"$folderName\"" >> updated_plugin_names.txt
            fi
        fi
    done
}

search_and_update

 

2. Revert Changes Script: This script reverts the changes made by the first script. It reads the folder names from the log file generated by the first script and sets the `isEnabled` key back to `true` for the corresponding plugins.

 

#!/bin/bash

# Function to revert changes made by the first script
revert_changes() {
    # Read plugin names from file
    while IFS= read -r folderName; do
        # Remove quotes and extract folder name
        folderName=$(echo "$folderName" | sed 's/"folderName": "\(.*\)"/\1/')
        # Find plugin directory by name
        dir=$(find . -maxdepth 1 -type d -name "*$folderName*")
        if [ -n "$dir" ]; then
            # Check if plugin.json exists and set "isEnabled" to true
            if [ -f "$dir/plugin.json" ]; then
                jq '.isEnabled = true' "$dir/plugin.json" > temp.json && mv temp.json "$dir/plugin.json"
            fi
        fi
    done < updated_plugin_names.txt
}

revert_changes

 

Using the Scripts:

Follow these steps to use the scripts:

  1. Copy Scripts to the Sisense Plugins Directory: Place both scripts (`search_and_update.sh` and `revert_changes.sh`) in the `/opt/sisense/storage/plugins` directory.
  2. Make Scripts Executable: Ensure that both scripts have execute permissions. You can set execute permissions using the `chmod` command:

 

chmod +x search_and_update.sh
chmod +x revert_changes.sh​

 

  • Execute the Search and Update Script: Run the `search_and_update.sh` script to update the `plugin.json` files:

 

./search_and_update.sh​

 

This script will update the `isEnabled` key to `false` for plugins with the corresponding folders and log the folder names in `updated_plugin_names.txt`.

  • Execute the Revert Changes Script (if needed): If you need to revert the changes made by the first script, run the `revert_changes.sh` script:

 

./revert_changes.sh​

 

This script will read the folder names from `updated_plugin_names.txt` and set the `isEnabled` key back to `true` for the corresponding plugins.

Conclusion:

By utilizing bash scripting, managing Sisense plugins becomes more efficient and less error-prone. These scripts automate the process of updating and reverting plugin configurations, saving time and ensuring consistency across your Sisense environment. Make sure to test these scripts in a safe environment before applying them to a production environment.

Disclaimer: Please note, that this blog post contains one possible custom workaround solution for users with similar use cases. We cannot guarantee that the custom code solution described in this post will work in every scenario or with every Sisense software version. As such, we strongly advise users to test solutions in their own environment prior to deploying them to ensure that the solutions proffered function as desired in their environment. For the avoidance of doubt, the content of this blog post is provided to you “as-is” and without warranty of any kind, express, implied or otherwise, including without limitation any warranty of security and or fitness for a particular purpose. The workaround solution described in this post incorporates custom coding which is outside the Sisense product development environment and is therefore not covered by not covered by Sisense warranty and support services.

Rate this article:
Version history
Last update:
‎05-09-2024 03:05 AM
Updated by: