잠토의 잠망경

[Splunk] python 연계 01 본문

공부/Splunk

[Splunk] python 연계 01

잠수함토끼 2020. 4. 3. 21:29

 

https://youtu.be/dc89nCWY35c

 

https://docs.splunk.com/Documentation/Splunk/latest/Search/Customsearchcommandshape

 

Custom search command example - Splunk Documentation

Download topic as PDF Custom search command example This following is an example of a custom search command called shape. The shape command categorizes events based on the event line count (tall or short) and line length (thin, wide, and very_wide) and whe

docs.splunk.com

 

1. app을 먼저 만든다.

2. 앱 만들기를 클릭한다.

3. 내용 채우기

4. 추가된 내용을 볼 수 있다.

 

5. app이 설치된 폴더로 이동한다.

 

6. pip install 진행한다.

$pip install -t . splunk-sdk

차가된 사항

7. python code를 작성한다. 파일이름(mycommand.py)

 

import sys
from splunklib.searchcommands import dispatch, StreamingCommand, Configuration

@Configuration()
class MyCommand(StreamingCommand):
    def stream(self, records):
        for record in records:
            record['hello'] = 'world'
            yield record

if __name__ == '__main__':
    dispatch(MyCommand, sys.argv, sys.stdin, sys.stdout, __name__)

 

 

8. 등록하기(commands.conf) 파일을 만든다.

파일 내용

[mycommand]
chunked=true
filename=mycommand.py

 

9. 재실행

10. 재실행

 

11. 사용자 권한 나눠주기 

 

 

 

12. 검색

index=main | mycommand | stats count by hello

 

 

Comments