X-Git-Url: http://git.squeep.com/?a=blobdiff_plain;f=scripts%2Fcreate_metrics_app.sh;fp=scripts%2Fcreate_metrics_app.sh;h=c42f5dde8c37dd059efe1633ecd712a497a2ec7f;hb=18bf82d7479b0bb767a657e1b7447529f9c2884f;hp=0000000000000000000000000000000000000000;hpb=07a48b9293e4046c50b5d424d60a1bf16c7cc198;p=akkoma diff --git a/scripts/create_metrics_app.sh b/scripts/create_metrics_app.sh new file mode 100755 index 000000000..c42f5dde8 --- /dev/null +++ b/scripts/create_metrics_app.sh @@ -0,0 +1,65 @@ +#!/bin/sh + +read -p "Instance URL (e.g https://example.com): " INSTANCE_URL + +echo "Creating oauth app..." + +RESP=$(curl \ + -XPOST \ + $INSTANCE_URL/api/v1/apps \ + --silent \ + --data-urlencode 'client_name=fedibash' \ + --data-urlencode 'redirect_uris=urn:ietf:wg:oauth:2.0:oob' \ + --data-urlencode 'scopes=admin:metrics' \ + --header "Content-Type: application/x-www-form-urlencoded" +) + +client_id=$(echo $RESP | jq -r .client_id) +client_secret=$(echo $RESP | jq -r .client_secret) + +if [ -z "$client_id" ]; then + echo "Could not create an app" + echo "$RESP" + exit 1 +fi + +echo "Please visit the following URL and input the code provided" +AUTH_URL="$INSTANCE_URL/oauth/authorize?client_id=$client_id&redirect_uri=urn:ietf:wg:oauth:2.0:oob&scope=admin:metrics&response_type=code" +if [ ! -z "$BROWSER" ]; then + $BROWSER $AUTH_URL +fi; + +echo $AUTH_URL + +read -p "Code: " CODE + +echo "Requesting code..." + +RESP=$(curl \ + -XPOST \ + $INSTANCE_URL/oauth/token \ + --silent \ + --header "Content-Type: application/x-www-form-urlencoded" \ + --data-urlencode "client_id=$client_id" \ + --data-urlencode "client_secret=$client_secret" \ + --data-urlencode "code=$CODE" \ + --data-urlencode "grant_type=authorization_code" \ + --data-urlencode 'redirect_uri=urn:ietf:wg:oauth:2.0:oob' \ + --data-urlencode "scope=admin:metrics" +) +echo $RESP +ACCESS_TOKEN="$(echo $RESP | jq -r .access_token)" + +echo "Token is $ACCESS_TOKEN" +DOMAIN=$(echo $INSTANCE_URL | sed -e 's/^https:\/\///') + +echo "Use the following config in your prometheus.yml: +- job_name: akkoma + scheme: https + authorization: + credentials: $ACCESS_TOKEN + metrics_path: /api/v1/akkoma/metrics + static_configs: + - targets: + - $DOMAIN +"