欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页

logstash-input-http用户名和密码方式请求

程序员文章站 2022-04-18 12:46:45
...

logstash.conf配置

input {
	http {
		# 类型,用于判断
		type => "desktop_message"
	    host => "68.61.113.52"
		port => "9601"
		# 请求头用户名、密码验证
		#需要在请求头加上参数:Authorization 
		#参数值Basic Base64("user:password"):Basic ZGVza3RvcF9tZXNzYWdlOmRlc2t0b3BfbWVzc2FnZQ==
		user => "desktop_message"
		password => "desktop_message"
	}
}

filter {
	if [type] == "desktop_message" {
		mutate {
			# 移除不需要的字段
			remove_field => ["headers","host"]
		}
	}
}
  
output {
	if [type] == "desktop_message" {
		elasticsearch {
		    # es地址,多个逗号隔开
			hosts => ["localhost:9200"]
			# 账号
			#user => ""
			# 密码
			#password => ""
			# 索引
			index => "desktop_message"
			# id
			document_id => "%{userMessageId}"
		}
	}
	
	stdout {
		codec => json_lines
	}
}

配置加上user、password后,需要在请求头加上参数:Authorization 参数值为:Basic Base64("user:password"),Basic 后有空格,我的帐号密码加密后的值为:ZGVza3RvcF9tZXNzYWdlOmRlc2t0b3BfbWVzc2FnZQ==

在线Base64加密:http://tool.chinaz.com/Tools/Base64.aspx

 

logstash-input-http用户名和密码方式请求

postman请求示例

 

 

 

logstash-input-http用户名和密码方式请求

官网文档:https://www.elastic.co/guide/en/logstash/current/plugins-inputs-http.html#plugins-inputs-http 

相关标签: elastic