Moving to bash 2
This commit is contained in:
parent
a3def897fa
commit
2de724da57
|
@ -1,12 +0,0 @@
|
||||||
[Unit]
|
|
||||||
Description=Prometheus Server
|
|
||||||
Documentation=https://prometheus.io/docs/introduction/overview/
|
|
||||||
After=network-online.target
|
|
||||||
|
|
||||||
[Service]
|
|
||||||
User=root
|
|
||||||
Restart=on-failure
|
|
||||||
ExecStart=/usr/bin/prometheus --config.file=/etc/prometheus/prometheus.yml
|
|
||||||
|
|
||||||
[Install]
|
|
||||||
WantedBy=multi-user.target
|
|
|
@ -1,5 +1,78 @@
|
||||||
#!/usr/bin/env bash
|
#!/usr/bin/env bash
|
||||||
|
|
||||||
|
|
||||||
|
function importDataSource()
|
||||||
|
{
|
||||||
|
local grURL="${1}/api/datasources" # Grafana API URL
|
||||||
|
local dsName=${2} # Datasource Name
|
||||||
|
local dsURL="${3}" # Datasource URL
|
||||||
|
local dsType="prometheus" # Datasource type
|
||||||
|
|
||||||
|
cmd="curl"
|
||||||
|
|
||||||
|
|
||||||
|
data=$(cat <<__EOF__
|
||||||
|
{"name":"${dsName}","type":"${dsType}","url":"${dsURL}","access":"direct"}
|
||||||
|
__EOF__
|
||||||
|
)
|
||||||
|
|
||||||
|
echo -ne "\tCreating datasource for Prometheus "
|
||||||
|
res=$(${cmd} "${grURL}" -H "Content-Type: application-json" --data-binary "${data}" 2>&1 )
|
||||||
|
excode=${?}
|
||||||
|
case $res in
|
||||||
|
*"already exists"*)
|
||||||
|
echo " ... [Exists]"
|
||||||
|
;;
|
||||||
|
*"Datasource added"*)
|
||||||
|
echo " ... [OK]"
|
||||||
|
;;
|
||||||
|
*)
|
||||||
|
echo " ... Ooops ${res}"
|
||||||
|
;;
|
||||||
|
esac
|
||||||
|
}
|
||||||
|
|
||||||
|
function importDashboardFromMarket()
|
||||||
|
{
|
||||||
|
local grURL="${1}/api/dashboards/import" # API URL to create new Dashboard
|
||||||
|
local dsName="${2}" # Datasource name (to link dashboard to data)
|
||||||
|
local dhID="${3}" # Dashboard ID in the market
|
||||||
|
local dhRev="${4}" # Dashboard Revision to download
|
||||||
|
local tmpFile=$(mktemp)
|
||||||
|
local dhFile=$(mktemp)
|
||||||
|
|
||||||
|
# URL To download the json file for dashboard
|
||||||
|
local pubDashBoardURL="https://grafana.com/api/dashboards/${dhID}/revisions/${dhRev}/download"
|
||||||
|
|
||||||
|
local cmd="curl"
|
||||||
|
|
||||||
|
local dh=$(${cmd} --silent ${pubDashBoardURL} 2>&1)
|
||||||
|
|
||||||
|
cat <<_EOF_ > ${tmpFile}
|
||||||
|
{
|
||||||
|
"inputs": [ { "name":"DS_LOCALHOST", "type":"datasource", "pluginId":"prometheus", "value":"${dsName}" } ],
|
||||||
|
"dashboard": { "title": "Surveillance Système", ${dh:1:-1} },
|
||||||
|
"folderId": 0,
|
||||||
|
"overwrite": true
|
||||||
|
}
|
||||||
|
_EOF_
|
||||||
|
|
||||||
|
res=$(${cmd} "${grURL}" -H "Content-Type: application-json" --data-binary "@${tmpFile}" 2>&1 )
|
||||||
|
excode=${?}
|
||||||
|
case $res in
|
||||||
|
*"\"imported\":true"*)
|
||||||
|
echo " ... [Overwrited]"
|
||||||
|
;;
|
||||||
|
*"Datasource added"*)
|
||||||
|
echo " ... [OK]"
|
||||||
|
;;
|
||||||
|
*)
|
||||||
|
echo " ... Ooops ${res}"
|
||||||
|
;;
|
||||||
|
esac
|
||||||
|
# rm -rf ${tmpFile}
|
||||||
|
}
|
||||||
|
|
||||||
grafanaHost=$(CreoleGet srvGrafanaIP 192.168.30.57)
|
grafanaHost=$(CreoleGet srvGrafanaIP 192.168.30.57)
|
||||||
grafanaPort=$(CreoleGet srvGrafanaPort 3000)
|
grafanaPort=$(CreoleGet srvGrafanaPort 3000)
|
||||||
grafanaUser="admin"
|
grafanaUser="admin"
|
||||||
|
@ -8,27 +81,11 @@ grafanaURL="http://${grafanaUser}:${grafanaPasswd}@${grafanaHost}:${grafanaPort}
|
||||||
datasource_name=$(CreoleGet promDataSource "prometheus")
|
datasource_name=$(CreoleGet promDataSource "prometheus")
|
||||||
promHost=$(CreoleGet adresse_ip_eth0)
|
promHost=$(CreoleGet adresse_ip_eth0)
|
||||||
promPort='9090'
|
promPort='9090'
|
||||||
|
datasourceURL="http://${promHost}:${promPort}"
|
||||||
|
|
||||||
|
importDataSource ${grafanaURL} ${datasource_name} ${datasourceURL}
|
||||||
cmd="curl"
|
echo
|
||||||
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 "
|
echo -ne "\tImporting Node Exporter Full Dashboard "
|
||||||
|
importDashboardFromMarket ${grafanaURL} ${datasource_name} 1860 11
|
||||||
|
|
||||||
|
rm -rf ${dashBoardFile}
|
||||||
|
|
Loading…
Reference in New Issue