Package: grafana-import
Grafana import ToolA python3 based application to play with grafana dashboards usingGrafana APIand a python interfacegrafana-clientThe aim of this tool is to:Export easilly an existing Grafana dashboard from a folder.Import a dashboard in JSON format into a Grafana.Remove a dashboardInstall using this repoinstall github repository.$pipinstallgit+https://github.com/peekjef72/grafana-import-tool.gitRequirements:bashpython >3.6python modules:jinja2grafana_client 2.0.0 what will pull the dependenciesrequestsidnaurllib3certifichardetAccess to a Grafana API server.ATokenof anAdminrole (grafana APIKey).ConfigurationThe configuration is stored in a YAML file.It contains 2 parts:general: for script env.debug: enable verbose (debug) trace (for dev only...)export_suffix: when exporting a dashboard, append that suffix to the file name. The suffix can contain plain text and pattern that is translated with strftime command.export_path: where to store the exported dashboards.import_path: where to load the dashboards before to import then into grafana server.grafana: for grafana access settings; you can define several grafana acces with different api_key or grafana server urllabel: a label to refer this grafana server default at leastprotocal,host,port: use to build the access urlverify_ssl: to check ssl certificate or nottoken: APIKEY with admin right from Grafana to access the REST API.search_api_limit: the maximum element to retrieve on search over API.example:---general:debug:falseimport_folder:test_importgrafana:default:protocol:httphost:localhostport:3000token:"____APIKEY____"search_api_limit:5000verify_ssl:true...Usagesbuild a directory structure:grafana-import/conf/grafana-import.yml
where your main configuration file isexports/
where your exported dashboards will be stored.imports/
where your dashboards to import are stored.then enter into your directory and type in you commands.usage:usage:grafana-import[-h][-a][-bBASE_PATH][-cCONFIG_FILE][-dDASHBOARD_NAME][-gGRAFANA_LABEL][-fGRAFANA_FOLDER][-iDASHBOARD_FILE][-o][-p][-v][-V][ACTION]playwithgrafanadashboardsjsonfiles.

positionalarguments:ACTIONactiontoperform.Isoneof'export','import'(default),or'remove'.export:lookupfordashboardnameinGrafanaanddumpittolocalfile.import:importalocaldashboardfile(previouslyexported)toGrafana.remove:lookupfordashboardnameinGrafanaandremoveitfromGrafanaserver.


optionalarguments:-h,--helpshowthishelpmessageandexit-a,--allow_newifadashboardwithsamenameexistsinananotherfolder,allowtocreateanewdashboardwithsamenameitthatfolder.-bBASE_PATH,--base_pathBASE_PATHsetbasedirectorytofinddefaultfiles.-cCONFIG_FILE,--config_fileCONFIG_FILEpathtoconfigfiles.-dDASHBOARD_NAME,--dashboard_nameDASHBOARD_NAMEnameofdashboardtoexport.-gGRAFANA_LABEL,--grafana_labelGRAFANA_LABELlabelintheconfigfilethatrepresentsthegrafanatoconnectto.-fGRAFANA_FOLDER,--grafana_folderGRAFANA_FOLDERthefoldernamewheretoimportintoGrafana.-iDASHBOARD_FILE,--dashboard_fileDASHBOARD_FILEpathtothedashboardfiletoimportintoGrafana.-o,--overwriteifadashboardwithsamenameexistsinfolder,overwriteitwiththisnewone.-p,--prettyuseJSONindentationwhenexportingorextractionofdashboards.-v,--verboseverbosemode;displaylogmessagetostdout.-V,--versiondisplayprogramversionandexit..import action preserves the version history.Example:importthe dashboard located in default directory imports to grafana folder "Applications"$grafana-import-imy-first-dashboard_202104011548.json-fApplications-o
OK:dashboardmy-first-dashboardimportedinto'Applications'.then you can go into Grafana Gui and find the folder Applicationsexportthe dashboard 'my-first-dashboard' to default export directory:$/usr/local/bin/grafana-import-d"my-first-dashboard"-pexportOK:dashboardexportedto'./exports/my-first-dashboard_20210401165925.json'.When the dashboard is not required anymore, you can remove it:removethe dashboard "my-first-dashboard" from folder "Applications"$grafana-import-fApplications-d"my-first-dashboard"remove
OK:dashboardmy-first-dashboardremovedfrom'Applications'.