[Logstash] logstash input telnet plugin.

Elastic/Logstash 2015. 8. 25. 17:18

logstash 에 telnet input 플러그인이 없어서 그냥 간단하게 만들었습니다.

용도는 특정 ip(hostname), port 들을 대상으로 잘 떠 있는지 점검하기 위함 입니다. :)


필요 하신 분들은 참고 하세요.

(빌드 된거 받아서 설치 하셔도 되고, 소스코드 받아서 빌드 한 신 후 사용하셔도 되고 그렇습니다.)


[파일 다운로드]


[git repository]

https://github.com/howookjeong/logstash-input-telnet


[run config]

bin/logstash -e '

  input {

    telnet{

      daemons => "localhost:9200|localhost:9301"

      interval => "60"

    }

  }


  output {stdout { codec => rubydebug }}

'


[rubydebug]

{

          "host" => "localhost",

          "port" => "9200",

       "message" => "success",

      "@version" => "1",

    "@timestamp" => "2015-08-25T07:06:30.128Z"

}

{

          "host" => "localhost",

          "port" => "9301",

       "message" => "failure",

      "@version" => "1",

    "@timestamp" => "2015-08-25T07:06:30.132Z"

}

※ 메시지 보시면 아시겠지만 정상인건 "success" 로 비정상인건 "failure" 로 나옵니다.

:

[git] git 대충 사용하기.

ITWeb/개발일반 2015. 8. 25. 17:02

git 대충 급할 때 대충 사용하기 위한 command


[git 처음 등록]

로컬 저장소 또는 생성한 프로젝트 위치에서 실행 합니다.

예) project-example

$ cd git/project-example

$ git init

$ git add *

$ git commit

$ git remote add origin “github 에 생성한 경로”

$ git push origin master


[파일 수정 후 반영]

$ git add 는 신규 파일인 경우 add 후 commit 수행

$ git commit 은 이미 등록된 파일에 대해서 수정이 완료 된 후 반영 하기 위해 수행

$ git push origin +master 이미 등록된 master를 로컬에 있는 것으로 덮었쓸 때


[원격 브랜치 체크아웃]

$ git checkout -t origin/브랜치명

또는

$ git checkout 로컬브랜치명 원격브랜치명

:

[Elasticsearch] java.lang.ClassNotFoundException: groovy.lang.GroovyClassLoader

Elastic/Elasticsearch 2015. 8. 24. 18:19

이 에러는 elasticsearch 프로젝트를 하나 만들어서 개발 하다 보면 경험하게 되는 메시지 입니다.


[에러]

java.lang.ClassNotFoundException: groovy.lang.GroovyClassLoader


이것은 groovy-all 과 lucene-expressions 에 대한 dependency 때문에 발생을 하는 것인데요.
이런 에러가 보기 싫으신 분들은 생성한 프로젝트의 pom.xml 에 아래 dependency 를 추가해 주시면 됩니다.


[pom.xml]

    <dependency>

      <groupId>org.codehaus.groovy</groupId>

      <artifactId>groovy-all</artifactId>

      <version>2.3.2</version>

      <scope>compile</scope>

      <optional>true</optional>

    </dependency>


    <dependency>

      <groupId>org.apache.lucene</groupId>

      <artifactId>lucene-expressions</artifactId>

      <version>4.10.2</version>

      <scope>compile</scope>

      <optional>true</optional>

    </dependency>

※ 여기서 주의 하셔야 할 점은 version 에 맞춰서 정보를 넣어 주셔야 한다는 것입니다.

※ elasticsearch 는 lucene 기반이기 때문에 version 은 꼭 확인 하셔야 합니다.


:

[Elasticsearch] SearchType.SCAN 사용 시 Aggregation 할 수 있나요?

Elastic/Elasticsearch 2015. 8. 20. 12:40

제가 분석하고 결과를 정리해 두고도 같은 실수를 하게 되내요.

별 내용은 아닙니다.

단순 정보의 보관 및 찾아보기 용으로 기록해 둡니다.


SearchType.SCAN 사용 시 Aggregation 기능은 사용 할 수 없습니다.


다만, 혼동하는 이유는 QueryDSL 작성 시 작성이 가능 하기 때문에 되는 것 처럼 착각을 하게 되는 것이구요.

실제 작성해서 실행 시켜 보면 아래와 같은 에러를 경험하게 됩니다.


[에러내용]

ElasticsearchIllegalArgumentException[aggregations are not supported with search_type=scan]


혹시라도 잘 못 알고 계시는 분들은 저 처럼 실수 하지 마시기 바랍니다. :)

:

[Elasticsearch] Scripting 을 이용한 Field Value 조작하기.

Elastic/Elasticsearch 2015. 8. 17. 14:59

정확하게 조작한다기 보다 저장된 document 의 field value 를 이용한다가 맞을 것 같습니다.

기본 참조 문서는 아래와 같습니다.

https://www.elastic.co/guide/en/elasticsearch/reference/current/modules-scripting.html


문서를 보셨으면 아시겠지만 기본 groovy 를 사용하게 되어 있습니다.

하지만 보안 이슈로 설정이 기본 false 입니다.

아래와 같이 설정을 변경해 주셔야 사용이 가능 합니다.


[Scripting Enable]

script.inline: on

또는

script.groovy.sandbox.enabled: true

※ 관련 설정에 대한 자세한 내용은 문서를 참고 하시면 됩니다.


아래는 문서 내용 snippet 입니다.


ValueDescription

off

scripting is turned off completely, in the context of the setting being set.

on

scripting is turned on, in the context of the setting being set.

sandbox

scripts may be executed only for languages that are sandboxed

그리고 추후 2.0.0 에서는 위 설정에서 groovy sandbox 는 deprecated 예정이니 참고하세요.

(https://www.elastic.co/guide/en/elasticsearch/reference/current/modules-scripting.html#_groovy_sandboxing)


설정을 해주셨으니 이제 value 에 접근하는 방법에 대해서 알아 보겠습니다.

문서에서는 총 3 가지 방법을 제시해 주고 있습니다.


[Value 접근]

# Document fields

_doc['field_name'].value or values


# Stored fields

_fields['field_name'].value


# Source field

_source['field_name']


※ 여기서 _fields 는 store 옵션을 true 로 하지 않으셨다면 에러가 발생 합니다.


value에 접근 하는 방법을 아셨으니 이 값을 이용한 연산을 어떻게 하는지도 궁금하실 겁니다.

위에서 말씀 드렸듯이 기본적인 language 는 groovy 입니다.

그렇기 때문에 groovy script 를 이용해서 연산 및 처리를 하시면 되겠습니다.


아래는 substring에 대한 커뮤니티의 질문에 대한 예제 코드 입니다.


[script_fields 샘플코드]

GET /test_index/_search

{

    "script_fields": {

        "field1_substring": {

            "script": "_doc['field1'].value"

        }

    }

}


GET /test_index/_search

{

    "script_fields": {

        "field1_substring": {

            "script": "_fields['field1'].value.substring(0, 5)"

        }

    }

}


GET /test_index/_search

{

    "script_fields": {

        "field1_substring": {

            "script": "_source.field1.substring(3, 10)"

        }

    }

}


※ script_fields 를 이용하게 되면 return 시 fields를 통해서 정보가 전달 됩니다. (즉, 필요한 field 가 있다면 추가로 선언해 주셔야 한다는 이야기 입니다.)

※ QueryDSL 을 보시면 아시겠지만 기본 query 구문이 없으면 match_all 로 동작 합니다.

※ 추가적으로 주의 할 점은 field 속성이 not_analyzed 인지 analyzed, store 인지 아닌지 확인 하시고 테스트 하시기 바랍니다.


: