eole-prometheus/postservice/88_grafana

35 lines
915 B
Bash
Executable File

#!/usr/bin/env bash
grafanaHost=$(CreoleGet srvGrafanaIP 192.168.30.57)
grafanaPort=$(CreoleGet srvGrafanaPort 3000)
grafanaUser="admin"
grafanaPasswd=$(CreoleGet grafana_admin_passwd admin)
grafanaURL="http://${grafanaUser}:${grafanaPasswd}@${grafanaHost}:${grafanaPort}"
datasource_name=$(CreoleGet promDataSource "prometheus")
promHost=$(CreoleGet adresse_ip_eth0)
promPort='9090'
cmd="curl"
url="${grafanaURL}/api/datasources"
data=$(cat <<__EOF__
{"name":"${datasource_name}","type":"prometheus","url":"http://${promHost}:${promPort}","access":"direct"}
__EOF__
)
echo -ne "\tCreating datasource for Prometheus "
res=$(${cmd} "${url}" -H "Content-Type: application-json" --data-binary "${data}" 2>&1 )
excode=${?}
case $res in
*"already exists"*)
echo " ... [Exists]"
;;
*"Datasource added"*)
echo " ... [OK]"
;;
esac
echo -ne "\tImporting Node Exporter Full Dashboard "