From 14dfc12bc7c16121d1ef0ba227c317a4be83faf0 Mon Sep 17 00:00:00 2001 From: IgorKha <2268209+IgorKha@users.noreply.github.com> Date: Sun, 10 Oct 2021 04:20:17 +0300 Subject: [PATCH] added run.sh --- .env | 6 +- .gitignore | 1 - docker-compose.yml | 6 +- prometheus/data/.gitignore | 4 + prometheus/prometheus.yml | 2 +- run.sh | 210 +++++++++++++++++++++++++++++++++++++ 6 files changed, 223 insertions(+), 6 deletions(-) delete mode 100644 .gitignore create mode 100644 prometheus/data/.gitignore create mode 100755 run.sh diff --git a/.env b/.env index cbdbfcf..5e11f71 100644 --- a/.env +++ b/.env @@ -1,2 +1,4 @@ -GF_ADMIN_USER=admin -GF_ADMIN_PASSWORD=mikrotik \ No newline at end of file +GF_ADMIN_USER=admin +GF_ADMIN_PASSWORD=mikrotik +CURRENT_USER=root +MIKROTIK_IP=192.168.88.1 \ No newline at end of file diff --git a/.gitignore b/.gitignore deleted file mode 100644 index f9cad2f..0000000 --- a/.gitignore +++ /dev/null @@ -1 +0,0 @@ -prometheus/data/* \ No newline at end of file diff --git a/docker-compose.yml b/docker-compose.yml index a634f55..108f843 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -16,11 +16,13 @@ services: prometheus: image: prom/prometheus - user: root + user: ${CURRENT_USER} container_name: mk_prometheus restart: always + environment: + - MIKROTIK_IP=${MIKROTIK_IP} volumes: - - ./prometheus/prometheus.yml:/etc/prometheus/prometheus.yml + - ./prometheus/:/etc/prometheus - ./prometheus/data/:/prometheus ports: - "9090:9090" diff --git a/prometheus/data/.gitignore b/prometheus/data/.gitignore new file mode 100644 index 0000000..86d0cb2 --- /dev/null +++ b/prometheus/data/.gitignore @@ -0,0 +1,4 @@ +# Ignore everything in this directory +* +# Except this file +!.gitignore \ No newline at end of file diff --git a/prometheus/prometheus.yml b/prometheus/prometheus.yml index cac0a98..99efb18 100644 --- a/prometheus/prometheus.yml +++ b/prometheus/prometheus.yml @@ -40,7 +40,7 @@ scrape_configs: - job_name: Mikrotik static_configs: - targets: - - 192.168.88.1 # SNMP device IP. + - 192.168.88.1 # SNMP device IP. metrics_path: /snmp params: module: [mikrotik] diff --git a/run.sh b/run.sh new file mode 100755 index 0000000..988a6e4 --- /dev/null +++ b/run.sh @@ -0,0 +1,210 @@ +#!/bin/sh +# +# You can also pass some arguments to script to set some these options: +# --config: change the user and password to grafana and specify the mikrotik IP address +# stop: stop docker containers +# For example: +# sh run.sh --config +# +# +# + +set -e + +REPO=Grafana-Mikrotik +ENV_FILE=${ENV_FILE:-.env} + +#? Colors +RED=$(printf '\033[31m') +GREEN=$(printf '\033[32m') +YELLOW=$(printf '\033[33m') +BLUE=$(printf '\033[34m') +BOLD=$(printf '\033[1m') +RESET=$(printf '\033[m') #? No Color + +BOLD=$(printf '\033[1m') + +#? Docker +DCUID=$(id -u) +DCGID=$(id -g) + +ask() { + local prompt default reply + + if [[ ${2:-} = 'Y' ]]; then + prompt='Y/n' + default='Y' + elif [[ ${2:-} = 'N' ]]; then + prompt='y/N' + default='N' + else + prompt='y/n' + default='' + fi + + while true; do + + #? Ask the question (not using "read -p" as it uses stderr not stdout) + echo -n "$1 [$prompt] " + + #? Read the answer (use /dev/tty in case stdin is redirected from somewhere else) + read -r reply /dev/null 2>&1 +} + +fmt_error() { + printf '%sError: %s%s\n' "$BOLD$RED" "$*" "$RESET" >&2 +} + +helper() { + if [ "$HELP" = yes ]; then + cat <