'2019/08/08'에 해당되는 글 2건

  1. 2019.08.08 [Shell Script] RESTful API Request
  2. 2019.08.08 [개발일반] Terraform 사용 시 에러 발생

[Shell Script] RESTful API Request

ITWeb/개발일반 2019. 8. 8. 16:09

가끔 필요 할 때가 있어서 작성해 봅니다.

 

Shell Script)

#!/bin/bash

CURRENT_DATE=$(date '+%Y-%m-%d')
NODES={"localhost:9200" "localhost:9201")
NODE=${NODES[0]}
INDEX="nginx-access-log-$CURRENT_DATE"
REQUEST_JSON_FILE="api-latency-over2sec-dsl.json"

sendMessageToSlack() {
  curl -XPOST -H "Content-Type: application/json; charset=utf-8" 
       -H "Authorization: Bearer xoxb-xxxxxxxxxxxxxxxxxxxxxxxxxx" 
       -d  "{ 'text': '$1'  }"  https://hooks.slack.com/services/xxxxxxxxxxxxxxxx
}

echo "curl --request POST --url http://$NODE/$INDEX/_search --header 'Content-Type: application/json' --data @$REQUEST_JSON_FILE"
RESPONSE_JSON=`curl --request POST --url http://$NODE/$INDEX/_search --header 'Content-Type: application/json' --data @$REQUEST_JSON_FILE`

echo "+++++++++++++++++++++++++++++++++++++++++++++"
echo $RESPONSE_JSON | jq .aggregations.long_latency.buckets[0].doc_count
echo "+++++++++++++++++++++++++++++++++++++++++++++"

INDEX_NAME=$2
ACTION=$3
ALIAS_NAME=$4
TARGET_DATE=$5

RESULT=`curl -s -o /dev/null -w "%{http_code}\n" -XPOST 'http://'$NODE'/_aliases' -H 'Content-Type: application/json' -d '
{
  "actions" : [
      { "'$ACTION'" : { "index" : "'$INDEX_NAME'-'$TARGET_DATE'", "alias" : "'$INDEX_NAME'-'$ALIAS_NAME'" }}
  ]
}'`

api-latency-over2sec-dsl.json)

{
  "query": {
    "constant_score": {
      "filter": {
        "bool": {
          "must": [
            {
              "range": {
                "response_time": {
                  "gte": "2"
                }
              }
            },
            {
              "range": {
                "@timestamp": {
                  "gte": "now-1h",
                  "lt": "now"
                }
              }
            }
          ]
        }
      }
    }
  },
  "size": 0,
  "aggs": {
    "long_latency": {
      "date_histogram": {
        "field": "@timestamp",
        "interval": "1h",
        "time_zone": "+09:00",
        "order" : { "_key" : "desc" }
      }
    }
  }
}
:

[개발일반] Terraform 사용 시 에러 발생

ITWeb/개발일반 2019. 8. 8. 09:17

아래 에러 메시지가 나오면 테라폼의 버전을 확인해 보라고 합니다.

뭐 에러 메시지에 이미 직관적으로 나와 있긴 하니까 쉽게 확인 가능 하실 듯 하내요.

 

$ terraform -v

 

에러 메시지)

Error refreshing state: state snapshot was created by Terraform v0.12.5, which is newer than current v0.12.0; upgrade to Terraform v0.12.5 or greater to work with this state

: