Humble implementation of a Unix like "tail" command for Elasticsearch using Python.
Tested with Logstash indexed content.
Install
$ git clone https://github.com/juan-domenech/elasticsearch-python.git
$ cd elasticsearch-python/
$ python elasticsearch-tail.py
Basic usage
The only mandatory parameter is --endpointExample:
$ python elasticsearch-tail.py --endpoint http://elk.example.com
By default the last 10 lines of log are displayed. You can change this behaviour with --docs or -n switch.
Example: To display the last 50 lines.
$ python elasticsearch-tail.py --endpoint http://elk.example.com -n 50
To have continuous output use -f or --nonstop
Example:
$ python elasticsearch-tail.py --endpoint http://elk.example.com -f
By default ES type = apache is used. You can select other types with --type
Examples:
$ python elasticsearch-tail.py --endpoint http://elk.example.com --type java
$ python elasticsearch-tail.py --endpoint http://elk.example.com --type apache
Advanced
By default the more recent Logstash Index is used. Optionally you can specify the desired index name using --index
Example:
$ python elasticsearch-tail.py --endpoint http://elk.example.com --index logstash-2016.08.08
When using --type java there are two other selectors available: --javalevel and --javaclass
Examples:
$ python elasticsearch-tail.py --endpoint http://elk.example.com --type java --javalevel ERROR
$ python elasticsearch-tail.py --endpoint http://elk.example.com --type java --javaclas error.handler.java.class
When using --type apache there are two other selectors available: --httpresponse and --httpmethod
Examples:
$ python elasticsearch-tail.py --endpoint http://elk.example.com --type apache --httpresponse 404
$ python elasticsearch-tail.py --endpoint http://elk.example.com --type apache --httpmethod POST
To display the native Elasticsearch timestamp of each event use --showheaders (Convenient when adding a |grep on the output to do additional filtering):
Example:
$ python elasticsearch-tail.py --endpoint http://elk.example.com --showheaders
To display events belonging to a particular host and ignore the rest use --hostname
Example:
$ python elasticsearch-tail.py --endpoint http://elk.example.com --hostname server1.example.com
Connection modes
The default protocol is HTTP (Port 80) but any other port can be specified under --endpoint
Example for HTTPS:
$ python elasticsearch-tail.py -f --endpoint https://elk.example.com
$ python elasticsearch-tail.py -f --endpoint https://elk.example.com:443
Example for Elasticsearch native port:
$ python elasticsearch-tail.py -f --endpoint http://elk.example.com:9200
Known issues
You need elasticsearch Python module installed
If you don't have it, run 'sudo pip install elasticsearch' to install it.
TLS error: "elasticsearch.exceptions.ConnectionError: ConnectionError(('Connection failed.', CannotSendRequest())) caused by: ConnectionError(('Connection failed.', CannotSendRequest()))"
Update urllib3 running 'sudo pip install --upgrade urllib3' or use a non HTTPS Endpoint URL.
Error: "check_index: No index found! Exiting"
The current script only cares for indices with the "logstash-" prefix. If you use any other prefix to index your logs it will fail.
If you think this shouldn't be this way please let me know in the comments.
Done for fun. Feel free to comment on bugs or additional desired features.
Thank you!
Thank you so much for providing information on this. It was very useful.
ReplyDeleteAviation Courses in Chennai
air hostess course in Chennai
airport courses in Chennai
Ground staff training in Chennai
Aviation Academy in Chennai
air hostess training in Chennai
airport management courses in Chennai
ground staff training in Chennai
iso 9001 certification in Delhi
ReplyDeleteiso 27001 certification services
ISO 9001 Certification in Noida
iso 22000 certification in Delhi
iso certification in noida
ReplyDeleteiso certification in delhi
ce certification in delhi
iso 14001 certification in delhi
iso 22000 certification cost
iso consultants in noida
we have provide the best fridge repair service.
ReplyDeleteWashing Machine Repair In Faridabad
LG Washing Machine Repair In Faridabad
Bosch Washing Machine Repair In Faridabad
Whirlpool Washing Machine Repair In Faridabad
Samsung Washing Machine Repair In Faridabad
Washing Machine Repair in Noida
godrej washing machine repair in noida
whirlpool Washing Machine Repair in Noida
IFB washing Machine Repair in Noida
LG Washing Machine Repair in Noida
we have provide the best ppc service.
ReplyDeleteppc company in gurgaon
website designing company in Gurgaon
PPC company in Noida
seo company in gurgaon
PPC company in Mumbai
PPC company in Chandigarh
Digital Marketing Company
Rice Bags Manufacturers
ReplyDeletePouch Manufacturers
fertilizer bag manufacturers
Lyrics with music
Great Article. Thank you for sharing! Really an awesome post for every one.
ReplyDeleteIEEE Final Year projects Project Centers in Chennai are consistently sought after. Final Year Students Projects take a shot at them to improve their aptitudes, while specialists like the enjoyment in interfering with innovation. For experts, it's an alternate ball game through and through. Smaller than expected IEEE Final Year project centers ground for all fragments of CSE & IT engineers hoping to assemble. Final Year Project Domains for IT It gives you tips and rules that is progressively critical to consider while choosing any final year project point.
Spring Framework has already made serious inroads as an integrated technology stack for building user-facing applications. Spring Framework Corporate TRaining the authors explore the idea of using Java in Big Data platforms.
Specifically, Spring Framework provides various tasks are geared around preparing data for further analysis and visualization. Spring Training in Chennai
Male escorts in Delhi
ReplyDeleteShweta gaur is one of the famous makeup artist in all over India. We are providing the best makeup artist courses and more other courses in over branches in Delhi.
ReplyDeleteMakeup Artist in Delhi
Makeup Artist
Best Makeup Artist in Delhi
Best Makeup Artist in East Delhi
Top Makeup Artist in Delhi
Top Makeup Artist in India
Bridal Makeup
Best Bridal Makeup Artist in Delhi
Bridal Makeup Artist in Delhi with Price
Bridal Makeup Artist in Delhi NCR
Top Bridal Makeup Artist in Delhi
Bridal Makeup in Delhi
Bridal Makeup Charges in Delhi
Bridal Makeup Packages Prices
Freelance Makeup Artist
Bridal Makeup Charges in Delhi
Freelance Bridal Makeup Artist in Delhi
Reception Makeup
Party makeup
Wedding makeup artist
Makeup Artist in Noida
PHP advancement is a well-known scripting language that is utilized to make intelligent and dynamic sites. Today, most business sites are made by utilizing php application development as it accompanies profoundly practical highlights and ease of use. So, organizations ready to make a customer's site with amazing information the executives highlights will require to recruit php development company. Our prime php website development improvement administrations start with understanding the client needs and stretches out to database driven top of the line custom undertaking web frameworks. Recruit devoted PHP engineers from Colan Infotech to plan php web development utilizing Photoshop, Flash etc. The php development India advancement administrations we offer are recorded underneath:
ReplyDeleteĐại lý vé máy bay Aivivu, tham khảo:
ReplyDeletevé máy bay đi Mỹ bao nhiêu tiền
đặt vé máy bay giá rẻ từ mỹ về việt nam
ve may bay tu canada ve viet nam
gia ve may bay vietjet tu han quoc ve viet nam
Thank you for the informative article. ufabet1688 Your writing style is interesting. I liked how you explained and I really enjoyed reading this post.
ReplyDeleteThe Casino at The Cosmopolitan of Las Vegas - MapYRO
ReplyDeleteCasino 충청북도 출장마사지 at The Cosmopolitan 당진 출장마사지 of Las 파주 출장마사지 Vegas 동두천 출장샵 - MapYRO 계룡 출장샵
Thanks for this great info of yours. This is so much a lot to do with my life. Lifesaver. Keep sharing with us. divorce lawyer
ReplyDeleteGreat write-up. Thanks for sharing. Keep up the good work! nondenominational church
ReplyDelete