diff --git a/deploy/deploy.sh b/deploy/deploy.sh index 41174ef73389c7cde9a4ce702c7872d6510bf36f..1029fbd638a321c0b5d09761fa19e0f2a4bb9f41 100755 --- a/deploy/deploy.sh +++ b/deploy/deploy.sh @@ -1046,22 +1046,9 @@ function parse_arg_grafana() { done } -function get_grafana_datasourcesID_byName() { - d_name="$1" - - d_id=$(curl -X GET -H "Content-Type: application/json" http://admin:admin@localhost:3000/api/datasources/id/${d_name} 2>/dev/null) - if echo $d_id | grep -q 'not found' ; then - echo_err_exit "Failed to find datasource ${d_name} in grafana" - fi - - d_id=${d_id##*:} - d_id=${d_id%?} - echo $d_id -} - function import_grafana_dashboard() { folder_uid="nErXDvCkzz" - + if [ "$DEPLOY_TYPE" == "local" ] ; then dashboard_path=${LOCAL_DEPLOY_SRCDIR} elif [ "$DEPLOY_TYPE" == "remote" ] ; then @@ -1075,9 +1062,9 @@ function import_grafana_dashboard() { http://admin:admin@localhost:3000/api/auth/keys` id=`echo $raw | jq '.id'` token=`echo $raw | jq '.key'` - token="${token#?}" + token="${token#?}" token="${token%?}" - auth="Authorization: Bearer "$token + auth="Authorization: Bearer "$token echo "id:"$id echo "token"$token @@ -1104,7 +1091,7 @@ function import_grafana_dashboard() { done inputs=${inputs%?}"]" echo $inputs - + #4. import dashboard for ele in "${DASHBOARD_LIST[@]}" do @@ -1165,80 +1152,74 @@ function deploy_grafana() { done name="Prometheus-dfs" - id=$(get_grafana_datasourcesID_byName ${name}) - result=$(curl -X PUT -H "Content-Type: application/json" -d '{"id":'${id}',"name":"'${name}'","type":"prometheus", + result=$(curl -X POST -H "Content-Type: application/json" -d '{"name":"'${name}'","type":"prometheus", "access":"proxy","url":"http://'${PROMETHEUS_ADDR}'","user":"","database":"", "basicAuth":false,"isDefault":true,"jsonData":{"httpMethod":"POST"},"readOnly":false}' \ -http://admin:admin@localhost:3000/api/datasources/${id} 2>/dev/null) - if ! echo $result | grep -q 'Datasource updated' ; then - echo_err_exit "Fail to update ${name} datesource in grafana" +http://admin:admin@localhost:3000/api/datasources/ 2>/dev/null) + if ! echo $result | grep -q 'Datasource added' ; then + echo_err_exit "Fail to add ${name} datesource in grafana" fi name="pyroscope-datasource" - id=$(get_grafana_datasourcesID_byName ${name}) - result=$(curl -X PUT -H "Content-Type: application/json" -d '{"id":'${id}',"name":"'${name}'","type":"pyroscope-datasource", + result=$(curl -X POST -H "Content-Type: application/json" -d '{"name":"'${name}'","type":"pyroscope-datasource", "access":"proxy","url":"","user":"","database":"","basicAuth":false,"isDefault":false, "jsonData":{"path":"http://'${PYROSCOPE_ADDR}'"},"readOnly":false}' \ -http://admin:admin@localhost:3000/api/datasources/${id} 2>/dev/null) - if ! echo $result | grep -q 'Datasource updated' ; then - echo_err_exit "Fail to update ${name} datesource in grafana" +http://admin:admin@localhost:3000/api/datasources/ 2>/dev/null) + if ! echo $result | grep -q 'Datasource added' ; then + echo_err_exit "Fail to add ${name} datesource in grafana" fi name="Elasticsearch-anteater_hybrid_model" - id=$(get_grafana_datasourcesID_byName ${name}) - result=$(curl -X PUT -H "Content-Type: application/json" -d '{"id":'${id}',"name":"'${name}'","type":"elasticsearch", + result=$(curl -X POST -H "Content-Type: application/json" -d '{"name":"'${name}'","type":"elasticsearch", "access":"proxy","url":"http://'${ES_ADDR}'","user":"", "database":"[gala_anteater_hybrid_model-]YYYY.MM.DD","basicAuth":false,"isDefault":false, "jsonData":{"includeFrozen":false,"interval":"Daily","logLevelField":"","logMessageField":"","maxConcurrentShardRequests":5,"timeField":"@timestamp"}, -"readOnly":false}' http://admin:admin@localhost:3000/api/datasources/${id} 2>/dev/null) - if ! echo $result | grep -q 'Datasource updated' ; then - echo_err_exit "Fail to update ${name} datesource in grafana" +"readOnly":false}' http://admin:admin@localhost:3000/api/datasources/ 2>/dev/null) + if ! echo $result | grep -q 'Datasource added' ; then + echo_err_exit "Fail to add ${name} datesource in grafana" fi name="Elasticsearch-cause_inference" - id=$(get_grafana_datasourcesID_byName ${name}) - result=$(curl -X PUT -H "Content-Type: application/json" -d '{"id":'${id}',"name":"'${name}'","type":"elasticsearch", + result=$(curl -X POST -H "Content-Type: application/json" -d '{"name":"'${name}'","type":"elasticsearch", "access":"proxy","url":"http://'${ES_ADDR}'","user":"", "database":"[gala_cause_inference-]YYYY.MM.DD","basicAuth":false,"isDefault":false, "jsonData":{"includeFrozen":false,"interval":"Daily","logLevelField":"","logMessageField":"","maxConcurrentShardRequests":5,"timeField":"@timestamp"}, -"readOnly":false}' http://admin:admin@localhost:3000/api/datasources/${id} 2>/dev/null) - if ! echo $result | grep -q 'Datasource updated' ; then - echo_err_exit "Fail to update ${name} datesource in grafana" +"readOnly":false}' http://admin:admin@localhost:3000/api/datasources/ 2>/dev/null) + if ! echo $result | grep -q 'Datasource added' ; then + echo_err_exit "Fail to add ${name} datesource in grafana" fi name="Elasticsearch-gala-event" - id=$(get_grafana_datasourcesID_byName ${name}) - result=$(curl -X PUT -H "Content-Type: application/json" -d '{"id":'${id}',"name":"'${name}'","type":"elasticsearch", + result=$(curl -X POST -H "Content-Type: application/json" -d '{"name":"'${name}'","type":"elasticsearch", "access":"proxy","url":"http://'${ES_ADDR}'","user":"", "database":"[gala_gopher_event-]YYYY.MM.DD","basicAuth":false,"isDefault":false, "jsonData":{"includeFrozen":false,"interval":"Daily","logLevelField":"","logMessageField":"","maxConcurrentShardRequests":5,"timeField":"@timestamp"}, -"readOnly":false}' http://admin:admin@localhost:3000/api/datasources/${id} 2>/dev/null) - if ! echo $result | grep -q 'Datasource updated' ; then - echo_warn "Fail to update ${name} datesource in grafana" +"readOnly":false}' http://admin:admin@localhost:3000/api/datasources/ 2>/dev/null) + if ! echo $result | grep -q 'Datasource added' ; then + echo_err_exit "Fail to add ${name} datesource in grafana" fi name="Elasticsearch-cause_inference_top" - id=$(get_grafana_datasourcesID_byName ${name}) - result=$(curl -X PUT -H "Content-Type: application/json" -d '{"id":'${id}',"name":"'${name}'","type":"elasticsearch", + result=$(curl -X POST -H "Content-Type: application/json" -d '{"name":"'${name}'","type":"elasticsearch", "access":"proxy","url":"http://'${ES_ADDR}'","user":"", "database":"[gala_cause_inference-]YYYY.MM.DD","basicAuth":false,"isDefault":false, "jsonData":{"includeFrozen":false,"interval":"Daily","logLevelField":"","logMessageField":"_source.Resource.top1","maxConcurrentShardRequests":5,"timeField":"@timestamp"}, -"readOnly":false}' http://admin:admin@localhost:3000/api/datasources/${id} 2>/dev/null) - if ! echo $result | grep -q 'Datasource updated' ; then - echo_err_exit "Fail to update ${name} datesource in grafana" +"readOnly":false}' http://admin:admin@localhost:3000/api/datasources/ 2>/dev/null) + if ! echo $result | grep -q 'Datasource added' ; then + echo_err_exit "Fail to add ${name} datesource in grafana" fi name="Elasticsearch-graph" - id=$(get_grafana_datasourcesID_byName ${name}) - result=$(curl -X PUT -H "Content-Type: application/json" -d '{"id":'${id}',"name":"'${name}'","type":"elasticsearch", + result=$(curl -X POST -H "Content-Type: application/json" -d '{"name":"'${name}'","type":"elasticsearch", "access":"proxy","url":"http://'${ES_ADDR}'","user":"", "database":"aops_graph2","basicAuth":false,"isDefault":false, "jsonData":{"includeFrozen":false,"logLevelField":"","logMessageField":"_source","maxConcurrentShardRequests":5,"timeField":"timestamp"}, -"readOnly":false}' http://admin:admin@localhost:3000/api/datasources/${id} 2>/dev/null) - if ! echo $result | grep -q 'Datasource updated' ; then - echo_err_exit "Fail to update ${name} datesource in grafana" +"readOnly":false}' http://admin:admin@localhost:3000/api/datasources/ 2>/dev/null) + if ! echo $result | grep -q 'Datasource added' ; then + echo_err_exit "Fail to add ${name} datesource in grafana" fi + # Create topo graph es resources curl -X PUT "${ES_ADDR}/aops_graph2?pretty" >/dev/null 2>&1 @@ -1253,7 +1234,7 @@ http://admin:admin@localhost:3000/api/datasources/${id} 2>/dev/null) install_rpm python3-pip fi fi - + if ! which jq >/dev/null ; then install_rpm jq fi