cancel
Showing results for 
Search instead for 
Did you mean: 

Automating Plugin Management in Sisense: A Bash Script Solution

taras
Sisense Team Member
Sisense Team Member

Introduction:

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 with permission to modify plugin files.
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.

Taras Skvarko
Technical Consultant
1 REPLY 1

taras
Sisense Team Member
Sisense Team Member

This post was converted to a Knowledgebase article. Find the updated article link here: https://community.sisense.com/t5/knowledge/automating-plugin-management-in-sisense-a-bash-script-sol...

Taras Skvarko
Technical Consultant