diff --git a/Dockerfile b/Dockerfile index 64b2c61..4675d39 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,6 +1,6 @@ FROM ruby:alpine -RUN apk update && apk upgrade && apk add perl perl-net-ssleay make g++ openssl +RUN apk update && apk upgrade && apk add perl perl-net-ssleay make g++ openssl curl WORKDIR /sectools/ @@ -8,6 +8,8 @@ RUN wget https://github.com/sullo/nikto/archive/master.tar.gz -P /sectools && \ tar zxvf /sectools/master.tar.gz -C /sectools && \ rm /sectools/master.tar.gz +HEALTHCHECK --interval=30s --timeout=5s --start-period=120s --retries=3 CMD curl --fail http://localhost:8080/status || exit 1 + COPY Gemfile src/ RUN bundle install --gemfile=/sectools/src/Gemfile diff --git a/README.md b/README.md index 1fda65a..427a677 100644 --- a/README.md +++ b/README.md @@ -1,4 +1,4 @@ -![Build Status](https://travis-ci.com/secureCodeBox/scanner-webserver-nikto.svg?token=2Rsf2E9Bq3FduSxRf6tz&branch=develop) +[![Build Status](https://travis-ci.com/secureCodeBox/scanner-webserver-nikto.svg?branch=develop)](https://travis-ci.com/secureCodeBox/scanner-webserver-nikto) [![License](https://img.shields.io/badge/License-Apache%202.0-blue.svg)](https://opensource.org/licenses/Apache-2.0) [![GitHub release](https://img.shields.io/github/release/secureCodeBox/scanner-webserver-nikto.svg)](https://github.com/secureCodeBox/scanner-webserver-nikto/releases/latest) diff --git a/lib/camunda_worker.rb b/lib/camunda_worker.rb index 245a599..7908c4d 100644 --- a/lib/camunda_worker.rb +++ b/lib/camunda_worker.rb @@ -44,9 +44,9 @@ def initialize(camunda_url, topic, variables, task_lock_duration = 3600000, poll @protected_engine = (ENV.has_key? 'ENGINE_BASIC_AUTH_USER') and (ENV.has_key? 'ENGINE_BASIC_AUTH_PASSWORD') @basic_auth_user = ENV.fetch('ENGINE_BASIC_AUTH_USER', '') @basic_auth_password = ENV.fetch('ENGINE_BASIC_AUTH_PASSWORD', '') - @repository_url = ENV.fetch('SCB_REPOSITORY_URL') - @branch = ENV.fetch('SCB_BRANCH') - @commit_id = ENV.fetch('SCB_COMMIT_ID') + @repository_url = ENV.fetch('SCB_REPOSITORY_URL', 'unknown') + @branch = ENV.fetch('SCB_BRANCH', 'unknown') + @commit_id = ENV.fetch('SCB_COMMIT_ID', 'unknown') Thread.new do sleep poll_interval @@ -112,6 +112,7 @@ def fetch_and_lock_task JSON.parse(res) end rescue => e + $logger.warn("Failed to fetch jobs") nil end end @@ -158,13 +159,14 @@ def http_post(url, payload = "") @last_connect = Time.now return nil else + $logger.warn "Unexpected http status code (#{response.code}) received." $logger.debug "Invalid response #{response.to_str} received." @last_connect = "ERROR" fail "Code #{response.code}: Invalid response #{response.to_str} received." end end rescue => e - $logger.debug "Error while connecting to #{url}" + $logger.warn "Error while connecting to #{url}." $logger.debug e.message raise StandardError.new end diff --git a/src/main.rb b/src/main.rb index e6d4523..42db01e 100644 --- a/src/main.rb +++ b/src/main.rb @@ -15,7 +15,7 @@ get '/status' do status 500 - if (healthcheck(client.last_connect) == "UP") + if (scanner_test == "SUCCESSFUL") status 200 end @@ -46,7 +46,7 @@ end def healthcheck(connection) - if (connection != "ERROR" && scanner_test == "SUCCESSFULL") + if (connection != "ERROR" && scanner_test == "SUCCESSFUL") return "UP" end return "DOWN" @@ -55,7 +55,7 @@ def healthcheck(connection) def scanner_test system('perl /sectools/nikto-master/program/nikto.pl -Version > /dev/null') if $? == 0 - return "SUCCESSFULL" + return "SUCCESSFUL" else return "FAILED" end