From 736e84601d37a43c3e7db3a17978a59f98c9092c Mon Sep 17 00:00:00 2001 From: Alessandro Aglietti Date: Tue, 6 Feb 2018 21:40:59 +0100 Subject: [PATCH 1/8] bash wrapper for get logs key and tail them --- docker/logentries_tail.sh | 33 +++++++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) create mode 100755 docker/logentries_tail.sh diff --git a/docker/logentries_tail.sh b/docker/logentries_tail.sh new file mode 100755 index 0000000..536fcb4 --- /dev/null +++ b/docker/logentries_tail.sh @@ -0,0 +1,33 @@ +#!/bin/bash + +display_usage() { + echo "Require JQ(https://stedolan.github.io/jq/) and lecli(https://github.com/rapid7/lecli)" + echo -e "\nUsage:\n ./logentries_tail.sh [logset_name] \n" + echo -e "\nUsage:\n ./logentries_tail.sh my_production_logset_name \n" +} + +# if less than two arguments supplied, display usage +if [ $# -le 0 ] +then + display_usage + exit 1 +fi + +# check whether user had supplied -h or --help . If yes display usage +if [[ ( $# == "--help") || $# == "-h" ]] +then + display_usage + exit 0 +fi + +logset_name=$1 + +echo -e "tail of ${logset_name}" + +# https://github.com/stedolan/jq/issues/1124#issuecomment-205346895 +jq_logset_key_query=(jq -r '.logsets[] | select(has("logs_info")) | select(.logs_info | length > 0) | .logs_info[] | select(.name | contains("'${logset_name}'") ) .id') +logset_key=`lecli get logsets | "${jq_logset_key_query[@]}" | uniq | sort | paste -s -` + +echo -e "${logset_name} log key: ${logset_key}\n" + +lecli tail events ${logset_key} \ No newline at end of file From afc7e2f18c7bcd9cdc70d79ff7f3c01b1472a581 Mon Sep 17 00:00:00 2001 From: Alessandro Aglietti Date: Tue, 6 Feb 2018 21:41:38 +0100 Subject: [PATCH 2/8] Docker container with lecli inside --- docker/.gitignore | 1 + docker/Dockerfile | 13 +++++++++++++ docker/requirements.txt | 1 + docker/root/.config/lecli/config.ini.sample | 11 +++++++++++ 4 files changed, 26 insertions(+) create mode 100644 docker/.gitignore create mode 100644 docker/Dockerfile create mode 100644 docker/requirements.txt create mode 100644 docker/root/.config/lecli/config.ini.sample diff --git a/docker/.gitignore b/docker/.gitignore new file mode 100644 index 0000000..26dd539 --- /dev/null +++ b/docker/.gitignore @@ -0,0 +1 @@ +root/.config/lecli/config.ini \ No newline at end of file diff --git a/docker/Dockerfile b/docker/Dockerfile new file mode 100644 index 0000000..fd752a0 --- /dev/null +++ b/docker/Dockerfile @@ -0,0 +1,13 @@ +FROM python:2.7-slim-jessie + +WORKDIR /usr/src/app + +RUN apt-get update && apt-get install -y jq && rm -rf /var/lib/apt/lists/* + +COPY . . +RUN pip install --no-cache-dir -r requirements.txt + +RUN cp logentries_tail.sh /usr/bin/letail +RUN chmod +x /usr/bin/letail + +CMD [ "lecli", "--version" ] diff --git a/docker/requirements.txt b/docker/requirements.txt new file mode 100644 index 0000000..e94fecc --- /dev/null +++ b/docker/requirements.txt @@ -0,0 +1 @@ +logentries-lecli \ No newline at end of file diff --git a/docker/root/.config/lecli/config.ini.sample b/docker/root/.config/lecli/config.ini.sample new file mode 100644 index 0000000..47cd9ca --- /dev/null +++ b/docker/root/.config/lecli/config.ini.sample @@ -0,0 +1,11 @@ +[Auth] +account_resource_id = +owner_api_key_id = +owner_api_key = +rw_api_key = +ro_api_key = + +[Cli_Favorites] + +[Url] +api_url = https://rest.logentries.com \ No newline at end of file From 52bb2cda9981cbbe0f1d4512f4f5d409a4de7b3a Mon Sep 17 00:00:00 2001 From: Alessandro Aglietti Date: Tue, 6 Feb 2018 21:41:56 +0100 Subject: [PATCH 3/8] docker-compose wrap all the things --- docker/docker-compose.yml | 8 ++++++++ 1 file changed, 8 insertions(+) create mode 100644 docker/docker-compose.yml diff --git a/docker/docker-compose.yml b/docker/docker-compose.yml new file mode 100644 index 0000000..107fc35 --- /dev/null +++ b/docker/docker-compose.yml @@ -0,0 +1,8 @@ +version: '3' +services: + lecli: + build: . + volumes: + - ./root/.config/lecli/config.ini:/root/.config/lecli/config.ini + dns: + - 8.8.8.8 \ No newline at end of file From 7fba94c99d3aaceefe0d3f6394feb49587a033e5 Mon Sep 17 00:00:00 2001 From: Alessandro Aglietti Date: Tue, 6 Feb 2018 21:42:01 +0100 Subject: [PATCH 4/8] readme --- docker/README.md | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) create mode 100644 docker/README.md diff --git a/docker/README.md b/docker/README.md new file mode 100644 index 0000000..3d41d7c --- /dev/null +++ b/docker/README.md @@ -0,0 +1,21 @@ +# Logentries CLI Docker container +A simply container with lecli installed + +## setup +`cp root/.config/config.ini.sample cp root/.config/config.ini` + +then edit `root/.config/config.ini` and add your logentries api keys + +## lecli arbitrary command +`docker-compose run --rm lecli lecli {lecli command args}` + +## test if api keys are working +`docker-compose run --rm lecli lecli get apikeys` + +## live tail +`docker-compose run --rm lecli letail {logset_name}` + +## tested on +ubuntu 16.04 LTS +Docker version 17.05.0-ce, build 89658be +docker-compose version 1.17.1, build 6d101fb \ No newline at end of file From a341088de959231b88bfb3344388fe8c3cea92de Mon Sep 17 00:00:00 2001 From: Alessandro Aglietti Date: Tue, 6 Feb 2018 21:46:14 +0100 Subject: [PATCH 5/8] renamed logset to logs --- docker/README.md | 2 +- docker/logentries_tail.sh | 16 ++++++++-------- 2 files changed, 9 insertions(+), 9 deletions(-) diff --git a/docker/README.md b/docker/README.md index 3d41d7c..318b5e6 100644 --- a/docker/README.md +++ b/docker/README.md @@ -13,7 +13,7 @@ then edit `root/.config/config.ini` and add your logentries api keys `docker-compose run --rm lecli lecli get apikeys` ## live tail -`docker-compose run --rm lecli letail {logset_name}` +`docker-compose run --rm lecli letail {logs_name}` ## tested on ubuntu 16.04 LTS diff --git a/docker/logentries_tail.sh b/docker/logentries_tail.sh index 536fcb4..8ebd294 100755 --- a/docker/logentries_tail.sh +++ b/docker/logentries_tail.sh @@ -2,8 +2,8 @@ display_usage() { echo "Require JQ(https://stedolan.github.io/jq/) and lecli(https://github.com/rapid7/lecli)" - echo -e "\nUsage:\n ./logentries_tail.sh [logset_name] \n" - echo -e "\nUsage:\n ./logentries_tail.sh my_production_logset_name \n" + echo -e "\nUsage:\n ./logentries_tail.sh [logs_name] \n" + echo -e "\nUsage:\n ./logentries_tail.sh my_production_logs_name \n" } # if less than two arguments supplied, display usage @@ -20,14 +20,14 @@ then exit 0 fi -logset_name=$1 +logs_name=$1 -echo -e "tail of ${logset_name}" +echo -e "tail of ${logs_name}" # https://github.com/stedolan/jq/issues/1124#issuecomment-205346895 -jq_logset_key_query=(jq -r '.logsets[] | select(has("logs_info")) | select(.logs_info | length > 0) | .logs_info[] | select(.name | contains("'${logset_name}'") ) .id') -logset_key=`lecli get logsets | "${jq_logset_key_query[@]}" | uniq | sort | paste -s -` +jq_logs_key_query=(jq -r '.logsets[] | select(has("logs_info")) | select(.logs_info | length > 0) | .logs_info[] | select(.name | contains("'${logs_name}'") ) .id') +logs_key=`lecli get logsets | "${jq_logs_key_query[@]}" | uniq | sort | paste -s -` -echo -e "${logset_name} log key: ${logset_key}\n" +echo -e "${logs_name} log key: ${logs_key}\n" -lecli tail events ${logset_key} \ No newline at end of file +lecli tail events ${logs_key} \ No newline at end of file From e04bde9e2f67a8274d6d64bac21134f588e7371a Mon Sep 17 00:00:00 2001 From: Alessandro Aglietti Date: Tue, 6 Feb 2018 21:50:20 +0100 Subject: [PATCH 6/8] updated travis with docker-compose build and run --- .travis.yml | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/.travis.yml b/.travis.yml index 0cd43df..2f1e93c 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,5 +1,10 @@ language: python +sudo: required +services: + - docker python: - "2.7" install: "pip install -r dev-requirements.pip" -script: pylint lecli && py.test tests +script: + - pylint lecli && py.test tests + - cd docker && docker-compose run From 5f8fad31298470e8df3a5518d779900d4bc3f947 Mon Sep 17 00:00:00 2001 From: Alessandro Aglietti Date: Tue, 6 Feb 2018 21:52:52 +0100 Subject: [PATCH 7/8] fix missing docker-compose service name during run inside travis --- .travis.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.travis.yml b/.travis.yml index 2f1e93c..5d83933 100644 --- a/.travis.yml +++ b/.travis.yml @@ -7,4 +7,4 @@ python: install: "pip install -r dev-requirements.pip" script: - pylint lecli && py.test tests - - cd docker && docker-compose run + - cd docker && docker-compose run lecli From 366f269512dd8d67431e00c0e9dfebed0d638f19 Mon Sep 17 00:00:00 2001 From: Alessandro Aglietti Date: Wed, 7 Feb 2018 09:34:01 +0100 Subject: [PATCH 8/8] readme fix --- docker/README.md | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/docker/README.md b/docker/README.md index 318b5e6..3ec1b0b 100644 --- a/docker/README.md +++ b/docker/README.md @@ -17,5 +17,8 @@ then edit `root/.config/config.ini` and add your logentries api keys ## tested on ubuntu 16.04 LTS + Docker version 17.05.0-ce, build 89658be -docker-compose version 1.17.1, build 6d101fb \ No newline at end of file + +docker-compose version 1.17.1, build 6d101fb +