netbox-script-manager


Namenetbox-script-manager JSON
Version 0.4.0 PyPI version JSON
download
home_pagehttps://github.com/kkthxbye-code/netbox_script_manager
SummaryImproved custom script support for netbox
upload_time2023-11-30 07:10:17
maintainer
docs_urlNone
authorkkthxbye-code
requires_python>=3.8
license
keywords netbox netbox-plugin
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            # NetBox Script Manager

Improved custom script support for netbox. Netbox version 3.5 removed several features related to custom scripts. This plugin attempts to undo these changes and add other improvements to scripts in netbox.

The plugin can be used in addition to the built-in script support and does not disable any netbox features.

## Features

* Scripts can be stored in nested modules.
* Scripts can rely on non-script module files.
* Scripts are loaded from a file-system folder.
* It's possible to sync scripts by pulling any git repo located in the `SCRIPT_ROOT`
* Name, group, description, task queues, comments and tags are editable in the UI.
* Task queue is selectable in the UI.
* Exceptions caused by errors in script files are displayed in the UI.
* Log messages are saved and displayed when the script is running allowing live output for long running scripts.
* It's possible to filter log lines by message and/or log level.
* Changelog entries are listed in a tab when viewing a finished script execution.
* It's possible to save script artifacts during the execution of a script. These artifacts will show up as downloadable files.
* It's possible to re-run scripts.

## What is not supported

* Reports
* DataSource/DataFile
* `load_json` and `load_yaml` convenience methods
* `script_order` - the ordering of scripts is instead based on `group` and `weight`

## Compatibility

| NetBox Version | Plugin Version |
|----------------|----------------|
|     3.5        |      0.1.0     |


## Installing

Add the plugin to `local_requirements.txt` or `plugin_requirements.txt` (netbox-docker):

```
netbox-script-manager
```

Enable the plugin in `/opt/netbox/netbox/netbox/configuration.py`,
 or if you use netbox-docker, your `/configuration/plugins.py` file:

```python
PLUGINS = [
    'netbox_script_manager'
]

PLUGINS_CONFIG = {
    "netbox_script_manager": {
        "SCRIPT_ROOT": "/path/to/script/folder/",
        "DEFAULT_QUEUE": "high"
    },
}
```

## Configuration

The following options are required:

* `SCRIPT_ROOT`: Path to the script folder containing the customscripts module. 

The following options are optional:

* `DEFAULT_QUEUE`: Specifies what queue scripts are run in by default. Defaults to the `default` queue.


## Migrating scripts

The most important change is to change the import and name of the base `Script` class.

Netbox Script:

```python
from extras.scripts import Script

class MyCustomScript(Script):
...
```

Netbox Script Manager Script:

```python
from netbox_script_manager.scripts import CustomScript

class MyCustomScript(CustomScript):
...
```

It is strongly recommended to do relative imports in your scripts, when using a nested structure or utility code.

```python
from .util import my_utility_method
from ..subfolder import myCustomScript
```

The alternative is to do an absolute import:

```python
from customscripts.nested_folder.util import my_utility_method
from customscripts.subfolder import myCustomScript
```

Please see the `Script folder` section for instructions regarding folder structure.

## Script folder

The loading of scripts is a little different with netbox-script-manager. The `SCRIPT_ROOT` plugin setting must be set to define the path of the custom scripts, however the scripts must be located in a folder named `customscripts` in this path.

A folder structure like this is required (`SCRIPT_ROOT` pointing to the `netboxscripts` folder):

```bash
├── netboxscripts # SCRIPT_ROOT
│   ├── customscripts # Scripts will be discovered in this module, must be present
│   │   ├── __init__.py
│   │   ├── nestedmodule
│   │   ├── root_script.py
│   │   └── util
│   └── __init__.py
```

The reason for requiring this layout with a `customscripts` folder is to avoid name collisions when dynamically loading scripts. It also makes it easier to clear the internal python module cache which is needed for reloading scripts.

Loading scripts is done either through the UI by pressing the `Load Scripts` button on the script view, or by calling the API endpoint `/api/plugins/script-manager/script-instances/load/`. Both of these require that the user has the `Can Add` action for the `Script Instance` object permission.

## Git Sync

> :grey_exclamation: git must be installed on the system.

> :grey_exclamation: The netbox user must have the `sync` additional action for the `Script Instance` object permission.

> :warning: git recurses parent directories until finding a git directory. Make sure the `SCRIPT_ROOT` is a git directory.

Netbox Script Manager has basic support for pulling down changes for git repositories. The Sync button is located on the script list and simply calls `git pull` on in the `SCRIPT_ROOT/customscripts` folder. If the git reposity requires authentication, it's recommended to setup SSH auth for the repo and provide the key in the users `$HOME/.ssh` folder.

If more advanced syncing is required, its recommended to handle this outside of netbox or alternatively use a custom script to do the sync.

## Screenshots

TODO

            

Raw data

            {
    "_id": null,
    "home_page": "https://github.com/kkthxbye-code/netbox_script_manager",
    "name": "netbox-script-manager",
    "maintainer": "",
    "docs_url": null,
    "requires_python": ">=3.8",
    "maintainer_email": "",
    "keywords": "netbox,netbox-plugin",
    "author": "kkthxbye-code",
    "author_email": "festll234@gmail.com",
    "download_url": "https://files.pythonhosted.org/packages/7c/33/0248d414e310d4afdea4128be9967b8b0b361c1384fd582ee58f784fb7c4/netbox-script-manager-0.4.0.tar.gz",
    "platform": null,
    "description": "# NetBox Script Manager\n\nImproved custom script support for netbox. Netbox version 3.5 removed several features related to custom scripts. This plugin attempts to undo these changes and add other improvements to scripts in netbox.\n\nThe plugin can be used in addition to the built-in script support and does not disable any netbox features.\n\n## Features\n\n* Scripts can be stored in nested modules.\n* Scripts can rely on non-script module files.\n* Scripts are loaded from a file-system folder.\n* It's possible to sync scripts by pulling any git repo located in the `SCRIPT_ROOT`\n* Name, group, description, task queues, comments and tags are editable in the UI.\n* Task queue is selectable in the UI.\n* Exceptions caused by errors in script files are displayed in the UI.\n* Log messages are saved and displayed when the script is running allowing live output for long running scripts.\n* It's possible to filter log lines by message and/or log level.\n* Changelog entries are listed in a tab when viewing a finished script execution.\n* It's possible to save script artifacts during the execution of a script. These artifacts will show up as downloadable files.\n* It's possible to re-run scripts.\n\n## What is not supported\n\n* Reports\n* DataSource/DataFile\n* `load_json` and `load_yaml` convenience methods\n* `script_order` - the ordering of scripts is instead based on `group` and `weight`\n\n## Compatibility\n\n| NetBox Version | Plugin Version |\n|----------------|----------------|\n|     3.5        |      0.1.0     |\n\n\n## Installing\n\nAdd the plugin to `local_requirements.txt` or `plugin_requirements.txt` (netbox-docker):\n\n```\nnetbox-script-manager\n```\n\nEnable the plugin in `/opt/netbox/netbox/netbox/configuration.py`,\n or if you use netbox-docker, your `/configuration/plugins.py` file:\n\n```python\nPLUGINS = [\n    'netbox_script_manager'\n]\n\nPLUGINS_CONFIG = {\n    \"netbox_script_manager\": {\n        \"SCRIPT_ROOT\": \"/path/to/script/folder/\",\n        \"DEFAULT_QUEUE\": \"high\"\n    },\n}\n```\n\n## Configuration\n\nThe following options are required:\n\n* `SCRIPT_ROOT`: Path to the script folder containing the customscripts module. \n\nThe following options are optional:\n\n* `DEFAULT_QUEUE`: Specifies what queue scripts are run in by default. Defaults to the `default` queue.\n\n\n## Migrating scripts\n\nThe most important change is to change the import and name of the base `Script` class.\n\nNetbox Script:\n\n```python\nfrom extras.scripts import Script\n\nclass MyCustomScript(Script):\n...\n```\n\nNetbox Script Manager Script:\n\n```python\nfrom netbox_script_manager.scripts import CustomScript\n\nclass MyCustomScript(CustomScript):\n...\n```\n\nIt is strongly recommended to do relative imports in your scripts, when using a nested structure or utility code.\n\n```python\nfrom .util import my_utility_method\nfrom ..subfolder import myCustomScript\n```\n\nThe alternative is to do an absolute import:\n\n```python\nfrom customscripts.nested_folder.util import my_utility_method\nfrom customscripts.subfolder import myCustomScript\n```\n\nPlease see the `Script folder` section for instructions regarding folder structure.\n\n## Script folder\n\nThe loading of scripts is a little different with netbox-script-manager. The `SCRIPT_ROOT` plugin setting must be set to define the path of the custom scripts, however the scripts must be located in a folder named `customscripts` in this path.\n\nA folder structure like this is required (`SCRIPT_ROOT` pointing to the `netboxscripts` folder):\n\n```bash\n\u251c\u2500\u2500 netboxscripts # SCRIPT_ROOT\n\u2502   \u251c\u2500\u2500 customscripts # Scripts will be discovered in this module, must be present\n\u2502   \u2502   \u251c\u2500\u2500 __init__.py\n\u2502   \u2502   \u251c\u2500\u2500 nestedmodule\n\u2502   \u2502   \u251c\u2500\u2500 root_script.py\n\u2502   \u2502   \u2514\u2500\u2500 util\n\u2502   \u2514\u2500\u2500 __init__.py\n```\n\nThe reason for requiring this layout with a `customscripts` folder is to avoid name collisions when dynamically loading scripts. It also makes it easier to clear the internal python module cache which is needed for reloading scripts.\n\nLoading scripts is done either through the UI by pressing the `Load Scripts` button on the script view, or by calling the API endpoint `/api/plugins/script-manager/script-instances/load/`. Both of these require that the user has the `Can Add` action for the `Script Instance` object permission.\n\n## Git Sync\n\n> :grey_exclamation: git must be installed on the system.\n\n> :grey_exclamation: The netbox user must have the `sync` additional action for the `Script Instance` object permission.\n\n> :warning: git recurses parent directories until finding a git directory. Make sure the `SCRIPT_ROOT` is a git directory.\n\nNetbox Script Manager has basic support for pulling down changes for git repositories. The Sync button is located on the script list and simply calls `git pull` on in the `SCRIPT_ROOT/customscripts` folder. If the git reposity requires authentication, it's recommended to setup SSH auth for the repo and provide the key in the users `$HOME/.ssh` folder.\n\nIf more advanced syncing is required, its recommended to handle this outside of netbox or alternatively use a custom script to do the sync.\n\n## Screenshots\n\nTODO\n",
    "bugtrack_url": null,
    "license": "",
    "summary": "Improved custom script support for netbox",
    "version": "0.4.0",
    "project_urls": {
        "Homepage": "https://github.com/kkthxbye-code/netbox_script_manager"
    },
    "split_keywords": [
        "netbox",
        "netbox-plugin"
    ],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "eb52afefb40a1cef122775d9d1f13914130b1a2a5d91d5d928164ba88637dfef",
                "md5": "0bce29585871e1c08e4d6a1b86f39a47",
                "sha256": "0a70da7e4a8ed22f4aaf362d340ee71d5449f96b9b917ed3109bea1968c130c4"
            },
            "downloads": -1,
            "filename": "netbox_script_manager-0.4.0-py2.py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "0bce29585871e1c08e4d6a1b86f39a47",
            "packagetype": "bdist_wheel",
            "python_version": "py2.py3",
            "requires_python": ">=3.8",
            "size": 48750,
            "upload_time": "2023-11-30T07:10:15",
            "upload_time_iso_8601": "2023-11-30T07:10:15.019510Z",
            "url": "https://files.pythonhosted.org/packages/eb/52/afefb40a1cef122775d9d1f13914130b1a2a5d91d5d928164ba88637dfef/netbox_script_manager-0.4.0-py2.py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "7c330248d414e310d4afdea4128be9967b8b0b361c1384fd582ee58f784fb7c4",
                "md5": "9da25498491182cc49f484b2c02537dc",
                "sha256": "d70e3271e930fd7d386c0be5340437bbe6ff97985e9be7134c500f933e9dad91"
            },
            "downloads": -1,
            "filename": "netbox-script-manager-0.4.0.tar.gz",
            "has_sig": false,
            "md5_digest": "9da25498491182cc49f484b2c02537dc",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": ">=3.8",
            "size": 41204,
            "upload_time": "2023-11-30T07:10:17",
            "upload_time_iso_8601": "2023-11-30T07:10:17.064769Z",
            "url": "https://files.pythonhosted.org/packages/7c/33/0248d414e310d4afdea4128be9967b8b0b361c1384fd582ee58f784fb7c4/netbox-script-manager-0.4.0.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2023-11-30 07:10:17",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "github_user": "kkthxbye-code",
    "github_project": "netbox_script_manager",
    "github_not_found": true,
    "lcname": "netbox-script-manager"
}
        
Elapsed time: 0.15225s