로그를 splunk에 보내야하는 python 프로그램이 있습니다. 우리의 인 Splunk 관리자는 다음과 같이 로그를 게시하는 서비스 컬렉터 HTTP 엔드 포인트를 만들었습니다파이썬에서 HTTP를 통해 splunk에 로그 항목을 작성하십시오.
- 인덱스
- 토큰 호스트 이름
- URI
우리는 찾을 수 없습니다
import splunklib.client as client
import splunklib.results as results_util
HOST="splunkcollector.hostname.com"
URI="services/collector/raw"
TOKEN="ABCDEFG-8A55-4ABB-HIJK-1A7E6637LMNO"
PORT=443
# Create a Service instance and log in
service = client.connect(
host=HOST,
port=PORT,
token=TOKEN)
# Retrieve the index for the data
myindex = service.indexes["cloud_custodian"]
# Submit an event over HTTP
myindex.submit("Dummy test python client log")
나는 알 수 있듯이 URI 변수를 사용하지 않습니다. 위의 코드 결과는 다음과 같습니다.
Traceback (most recent call last):
File "splunk_log.py", line 15, in <module>
myindex = service.indexes["cloud_custodian"]
File "/usr/local/lib/python2.7/site-packages/splunklib/client.py", line 1230, in __getitem__
raise KeyError(key)
KeyError: UrlEncoded('cloud_custodian')
'service.indexes.keys()'로 색인을 나열하려고하면 어떤 결과가 발생합니까? – zwer
'AttributeError : 'Indexes'객체에 'keys'속성이 없습니다. – Lightbeard
아, 사용자 정의 유형을 좋아해야합니다 ... about : print ("service.indexes의 x에 str (x)) ' – zwer