Moving to bash
This commit is contained in:
parent
3df296b366
commit
a3def897fa
|
@ -1,51 +1,34 @@
|
||||||
#!/usr/bin/env python
|
#!/usr/bin/env bash
|
||||||
# -*- coding: utf-8 -*-
|
|
||||||
|
|
||||||
import os
|
grafanaHost=$(CreoleGet srvGrafanaIP 192.168.30.57)
|
||||||
import requests
|
grafanaPort=$(CreoleGet srvGrafanaPort 3000)
|
||||||
import json
|
|
||||||
|
|
||||||
from creole.client import CreoleClient
|
|
||||||
|
|
||||||
creole = c = CreoleClient()
|
|
||||||
|
|
||||||
grafanaHost = creole.get_creole('srvGrafanaIP','127.0.0.1')
|
|
||||||
grafanaPort = creole.get_creole('srvGrafanaPort', '3000')
|
|
||||||
grafanaURL = os.path.join('http://', '%s:%s' % (grafanaHost, grafanaPort))
|
|
||||||
grafanaUser="admin"
|
grafanaUser="admin"
|
||||||
grafanaPasswd = creole.get_creole('grafana_admin_passwd')
|
grafanaPasswd=$(CreoleGet grafana_admin_passwd admin)
|
||||||
datasource_name = creole.get_creole('promDataSource',"prometheus")
|
grafanaURL="http://${grafanaUser}:${grafanaPasswd}@${grafanaHost}:${grafanaPort}"
|
||||||
promHost = creole.get_creole('addresse_ip_eth0')
|
datasource_name=$(CreoleGet promDataSource "prometheus")
|
||||||
|
promHost=$(CreoleGet adresse_ip_eth0)
|
||||||
promPort='9090'
|
promPort='9090'
|
||||||
|
|
||||||
session = requests.Session()
|
|
||||||
login_post = session.post (
|
cmd="curl"
|
||||||
os.path.join(grafanaURL, 'login'),
|
url="${grafanaURL}/api/datasources"
|
||||||
data=json.dumps({
|
|
||||||
'user': grafanaUser,
|
data=$(cat <<__EOF__
|
||||||
'email': '',
|
{"name":"${datasource_name}","type":"prometheus","url":"http://${promHost}:${promPort}","access":"direct"}
|
||||||
'password': grafanaPasswd
|
__EOF__
|
||||||
}),
|
|
||||||
headers={'content-type': 'application/json'}
|
|
||||||
)
|
)
|
||||||
|
|
||||||
# Get list of datasources
|
echo -ne "\tCreating datasource for Prometheus "
|
||||||
datasources_get = session.get(os.path.join(grafanaURL, 'api', 'datasources'))
|
res=$(${cmd} "${url}" -H "Content-Type: application-json" --data-binary "${data}" 2>&1 )
|
||||||
datasources = datasources_get.json()
|
excode=${?}
|
||||||
|
case $res in
|
||||||
|
*"already exists"*)
|
||||||
|
echo " ... [Exists]"
|
||||||
|
;;
|
||||||
|
*"Datasource added"*)
|
||||||
|
echo " ... [OK]"
|
||||||
|
;;
|
||||||
|
esac
|
||||||
|
|
||||||
if datasources['message'] == "Unauthorized" :
|
echo -ne "\tImporting Node Exporter Full Dashboard "
|
||||||
exit(34)
|
|
||||||
|
|
||||||
# Add new datasource
|
|
||||||
datasources_put = session.put(
|
|
||||||
os.path.join(grafanaURL, 'api', 'datasources'),
|
|
||||||
data=json.dumps({
|
|
||||||
'access': 'direct',
|
|
||||||
'name': datasource_name,
|
|
||||||
'type': 'prometheus',
|
|
||||||
'url': 'http://%s:%u' % (promHost, promPort),
|
|
||||||
'basicAuth': 'false',
|
|
||||||
'withCredentials': 'false'
|
|
||||||
}),
|
|
||||||
headers={'content-type': 'application/json'}
|
|
||||||
)
|
|
||||||
|
|
Loading…
Reference in New Issue