Moving to bash

This commit is contained in:
Philippe Caseiro 2018-06-04 17:01:42 +02:00
parent 3df296b366
commit a3def897fa
1 changed files with 26 additions and 43 deletions

69
postservice/88_grafana Normal file → Executable file
View File

@ -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 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'
from creole.client import CreoleClient
creole = c = CreoleClient() cmd="curl"
url="${grafanaURL}/api/datasources"
grafanaHost = creole.get_creole('srvGrafanaIP','127.0.0.1') data=$(cat <<__EOF__
grafanaPort = creole.get_creole('srvGrafanaPort', '3000') {"name":"${datasource_name}","type":"prometheus","url":"http://${promHost}:${promPort}","access":"direct"}
grafanaURL = os.path.join('http://', '%s:%s' % (grafanaHost, grafanaPort)) __EOF__
grafanaUser = "admin"
grafanaPasswd = creole.get_creole('grafana_admin_passwd')
datasource_name = creole.get_creole('promDataSource',"prometheus")
promHost = creole.get_creole('addresse_ip_eth0')
promPort = '9090'
session = requests.Session()
login_post = session.post (
os.path.join(grafanaURL, 'login'),
data=json.dumps({
'user': grafanaUser,
'email': '',
'password': grafanaPasswd
}),
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'}
)