diff --git a/.bonsai.yml b/.bonsai.yml index 253436a..d5282f3 100644 --- a/.bonsai.yml +++ b/.bonsai.yml @@ -3,7 +3,7 @@ description: "#{repo}" builds: - platform: "alpine" arch: "amd64" - asset_filename: "monitoring-plugins-alpine_#{version}_linux_amd64.tar.gz" + asset_filename: "monitoring-plugins-alpine_linux_amd64_#{version}.tar.gz" sha_filename: "#{repo}_#{version}_sha512-checksums.txt" filter: - "entity.system.os == 'linux'" @@ -12,7 +12,7 @@ builds: - platform: "amazon1" arch: "amd64" - asset_filename: "monitoring-plugins-amazon1_#{version}_linux_amd64.tar.gz" + asset_filename: "monitoring-plugins-debian8_linux_amd64_#{version}.tar.gz" sha_filename: "#{repo}_#{version}_sha512-checksums.txt" filter: - "entity.system.os == 'linux'" @@ -24,7 +24,7 @@ builds: - platform: "amazon2" arch: "amd64" - asset_filename: "monitoring-plugins-amazon2_#{version}_linux_amd64.tar.gz" + asset_filename: "monitoring-plugins-debian8_linux_amd64_#{version}.tar.gz" sha_filename: "#{repo}_#{version}_sha512-checksums.txt" filter: - "entity.system.os == 'linux'" @@ -34,7 +34,7 @@ builds: - platform: "centos6" arch: "amd64" - asset_filename: "monitoring-plugins-centos6_#{version}_linux_amd64.tar.gz" + asset_filename: "monitoring-plugins-centos6_linux_amd64_#{version}.tar.gz" sha_filename: "#{repo}_#{version}_sha512-checksums.txt" filter: - "entity.system.os == 'linux'" @@ -44,7 +44,7 @@ builds: - platform: "centos7" arch: "amd64" - asset_filename: "monitoring-plugins-centos7_#{version}_linux_amd64.tar.gz" + asset_filename: "monitoring-plugins-debian8_linux_amd64_#{version}.tar.gz" sha_filename: "#{repo}_#{version}_sha512-checksums.txt" filter: - "entity.system.os == 'linux'" @@ -54,7 +54,7 @@ builds: - platform: "centos8" arch: "amd64" - asset_filename: "monitoring-plugins-centos8_#{version}_linux_amd64.tar.gz" + asset_filename: "monitoring-plugins-debian8_linux_amd64_#{version}.tar.gz" sha_filename: "#{repo}_#{version}_sha512-checksums.txt" filter: - "entity.system.os == 'linux'" @@ -64,7 +64,7 @@ builds: - platform: "debian8" arch: "amd64" - asset_filename: "monitoring-plugins-debian8_#{version}_linux_amd64.tar.gz" + asset_filename: "monitoring-plugins-debian8_linux_amd64_#{version}.tar.gz" sha_filename: "#{repo}_#{version}_sha512-checksums.txt" filter: - "entity.system.os == 'linux'" @@ -74,7 +74,7 @@ builds: - platform: "debian9" arch: "amd64" - asset_filename: "monitoring-plugins-debian9_#{version}_linux_amd64.tar.gz" + asset_filename: "monitoring-plugins-debian8_linux_amd64_#{version}.tar.gz" sha_filename: "#{repo}_#{version}_sha512-checksums.txt" filter: - "entity.system.os == 'linux'" @@ -84,7 +84,7 @@ builds: - platform: "debian10" arch: "amd64" - asset_filename: "monitoring-plugins-debian10_#{version}_linux_amd64.tar.gz" + asset_filename: "monitoring-plugins-debian8_linux_amd64_#{version}.tar.gz" sha_filename: "#{repo}_#{version}_sha512-checksums.txt" filter: - "entity.system.os == 'linux'" @@ -94,7 +94,7 @@ builds: - platform: "debian11" arch: "amd64" - asset_filename: "monitoring-plugins-debian11_#{version}_linux_amd64.tar.gz" + asset_filename: "monitoring-plugins-debian8_linux_amd64_#{version}.tar.gz" sha_filename: "#{repo}_#{version}_sha512-checksums.txt" filter: - "entity.system.os == 'linux'" @@ -104,7 +104,7 @@ builds: - platform: "ubuntu1404" arch: "amd64" - asset_filename: "monitoring-plugins-ubuntu1404_#{version}_linux_amd64.tar.gz" + asset_filename: "monitoring-plugins-debian8_linux_amd64_#{version}.tar.gz" sha_filename: "#{repo}_#{version}_sha512-checksums.txt" filter: - "entity.system.os == 'linux'" @@ -114,7 +114,7 @@ builds: - platform: "ubuntu1604" arch: "amd64" - asset_filename: "monitoring-plugins-ubuntu1604_#{version}_linux_amd64.tar.gz" + asset_filename: "monitoring-plugins-debian8_linux_amd64_#{version}.tar.gz" sha_filename: "#{repo}_#{version}_sha512-checksums.txt" filter: - "entity.system.os == 'linux'" @@ -124,7 +124,7 @@ builds: - platform: "ubuntu1804" arch: "amd64" - asset_filename: "monitoring-plugins-ubuntu1804_#{version}_linux_amd64.tar.gz" + asset_filename: "monitoring-plugins-debian8_linux_amd64_#{version}.tar.gz" sha_filename: "#{repo}_#{version}_sha512-checksums.txt" filter: - "entity.system.os == 'linux'" @@ -134,7 +134,7 @@ builds: - platform: "ubuntu2004" arch: "amd64" - asset_filename: "monitoring-plugins-ubuntu2004_#{version}_linux_amd64.tar.gz" + asset_filename: "monitoring-plugins-debian8_linux_amd64_#{version}.tar.gz" sha_filename: "#{repo}_#{version}_sha512-checksums.txt" filter: - "entity.system.os == 'linux'" @@ -144,7 +144,7 @@ builds: - platform: "ubuntu2204" arch: "amd64" - asset_filename: "monitoring-plugins-ubuntu2204_#{version}_linux_amd64.tar.gz" + asset_filename: "monitoring-plugins-debian8_linux_amd64_#{version}.tar.gz" sha_filename: "#{repo}_#{version}_sha512-checksums.txt" filter: - "entity.system.os == 'linux'" @@ -154,7 +154,7 @@ builds: - platform: "xcp-ng8" arch: "amd64" - asset_filename: "monitoring-plugins-centos7_#{version}_linux_amd64.tar.gz" + asset_filename: "monitoring-plugins-debian8_linux_amd64_#{version}.tar.gz" sha_filename: "#{repo}_#{version}_sha512-checksums.txt" filter: - "entity.system.os == 'linux'" diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index 1bfe197..74806ff 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -3,7 +3,6 @@ on: push: tags: - '*' - jobs: build: name: Publish binaries @@ -11,21 +10,15 @@ jobs: steps: - uses: actions/checkout@v2 - name: Build - run: ./travis-build.sh - env: - TRAVIS_REPO_SLUG: ${{github.repository}} - TRAVIS_TAG: ${{github.ref_name}} - FULL_PRUNE: 1 - - name: Sha512sum - run: cd dist && sha512sum ./*.tar.gz > "./monitoring-plugins_${TRAVIS_TAG}_sha512-checksums.txt" + run: ./scripts/build_and_validate.sh env: - TRAVIS_REPO_SLUG: ${{github.repository}} - TRAVIS_TAG: ${{github.ref_name}} + ASSET_VERSION: ${{github.ref_name}} + ASSET_REPONAME: monitoring-plugins - name: Upload binaries to release uses: svenstaro/upload-release-action@v2 with: repo_token: ${{ secrets.GITHUB_TOKEN }} - file: dist/* + file: assets/* tag: ${{ github.ref_name }} overwrite: true file_glob: true diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml new file mode 100644 index 0000000..1376a14 --- /dev/null +++ b/.github/workflows/test.yml @@ -0,0 +1,15 @@ +name: Test +on: [push] + +jobs: + build: + name: Build and Validate + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v2 + - name: Build and Validate + run: ./scripts/build_and_validate.sh + env: + ASSET_VERSION: ${{github.sha}} + ASSET_REPONAME: monitoring-plugins + diff --git a/.travis.yml b/.travis.yml deleted file mode 100644 index 92e6305..0000000 --- a/.travis.yml +++ /dev/null @@ -1,21 +0,0 @@ -language: c -compiler: -- gcc -services: -- docker -script: -- ./travis-build.sh -before_deploy: -- bash -c "[ ! -d bonsai/ ] && git clone https://github.com/sensu/sensu-go-bonsai-asset.git - bonsai || echo 'bonsai/ exists, skipping git clone'" -deploy: -- provider: script - script: ./travis-github-upload.sh - cleanup: false - skip_cleanup: true - on: - tags: true - all_branches: true -env: - global: - secure: jZIippZkdDlTLXTohWa/FTZQ/k16dfzefitCpXJpe6UxbWVF0zQrl1kfweZTh+jAQNXZoUZMAIiAYjMB0G9QZWVS2vtrl9sH53yiUC8q+R4DypTUpkOU54p1xxfyKTF4k9jzogKqjlIkH6n91XwlZsqfj1/dL0PKstfNXeGpqWWP1dCRhZftt8WWPdSTXASn0XqPWMqTEOey48CggZxWDUsqzYGjwvdgy5ZSjGTVH/SqsTNTksGV6QOaZ3WPk/PPr2sHBVSfOe9K3jPcau1P6zy17fvpwZxyTKR1ExrTjiB6WFE+cAMGs6vj5XMD3ZcWVn0nvaE3/WTjY4wn0tbvfQHzBQTMfi8dz4Fndc/gq2ioLswASQyqPmwcGva/GJ4M+R2hcREmTqhmwuRhK4gx+7vVD4WYsR7xNuD/vtOlDQpZnPxwSF9hvhYmlGMUC0vzPWuCChi/kM9tVDvtTH66W96A/lqyNUQbLIcLpyBb7jGUCckqGmJnrsuBuN+dG9Aj16cyElPKYXDGpk05zLzAVf0IVS05mAL3MplLgKDfymhmET9s6h9D1lu8KjYA8EWDwdIZH5YAspJIfbSc9cbcHrzVcuvFu1bks178Eck6vN9Cz8A65Zu/Aw4OjNoUBI/OPxpdZlAL4+MUe/7jCSn5ZnlH9ulehzWOzeZdf0VSlxI= diff --git a/builds/disabled/.touch b/builds/disabled/.touch new file mode 100644 index 0000000..e69de29 diff --git a/builds/enabled/.touch b/builds/enabled/.touch new file mode 100644 index 0000000..e69de29 diff --git a/Dockerfile.alpine b/builds/enabled/alpine_linux_amd64/Dockerfile similarity index 100% rename from Dockerfile.alpine rename to builds/enabled/alpine_linux_amd64/Dockerfile diff --git a/builds/enabled/alpine_linux_amd64/test_platforms b/builds/enabled/alpine_linux_amd64/test_platforms new file mode 100644 index 0000000..195132c --- /dev/null +++ b/builds/enabled/alpine_linux_amd64/test_platforms @@ -0,0 +1 @@ +frolvlad/alpine-bash diff --git a/Dockerfile.centos6 b/builds/enabled/centos6_linux_amd64/Dockerfile similarity index 100% rename from Dockerfile.centos6 rename to builds/enabled/centos6_linux_amd64/Dockerfile diff --git a/builds/enabled/centos6_linux_amd64/test_platforms b/builds/enabled/centos6_linux_amd64/test_platforms new file mode 100644 index 0000000..decb196 --- /dev/null +++ b/builds/enabled/centos6_linux_amd64/test_platforms @@ -0,0 +1 @@ +centos:6 amazonlinux:1 amazonlinux:2 centos:7 diff --git a/Dockerfile.debian8 b/builds/enabled/debian8_linux_amd64/Dockerfile similarity index 100% rename from Dockerfile.debian8 rename to builds/enabled/debian8_linux_amd64/Dockerfile diff --git a/builds/enabled/debian8_linux_amd64/test_platforms b/builds/enabled/debian8_linux_amd64/test_platforms new file mode 100644 index 0000000..3cb7d8a --- /dev/null +++ b/builds/enabled/debian8_linux_amd64/test_platforms @@ -0,0 +1 @@ +debian:8 amazonlinux:1 amazonlinux:2 debian:9 debian:10 debian:11 ubuntu:22.04 ubuntu:20.04 ubuntu:18.04 ubuntu:16.04 ubuntu:14.04 centos:7 centos:8 rockylinux:8 diff --git a/create-sensu-asset b/create-sensu-asset index 69fec2d..8685a19 100755 --- a/create-sensu-asset +++ b/create-sensu-asset @@ -177,7 +177,7 @@ if [[ $ASSET_ARCH = "_x86_64" ]]; then export ASSET_ARCH="_amd64" fi -ASSET="${OUTPUT_DIR}/${ASSET_NAME}${ASSET_VERSION}${ASSET_OS}${ASSET_ARCH}.tar.gz" +ASSET="${OUTPUT_DIR}/${ASSET_NAME}${ASSET_OS}${ASSET_ARCH}${ASSET_VERSION}.tar.gz" echo ""; echo "Packaging contents of ${PKG_DIR} into ${ASSET}"; echo ""; diff --git a/old/Dockerfile.alpine b/old/Dockerfile.alpine new file mode 100644 index 0000000..8588fa0 --- /dev/null +++ b/old/Dockerfile.alpine @@ -0,0 +1,21 @@ +FROM alpine:latest as builder + +ARG SENSU_GO_ASSET_NAME="monitoring-plugins-alpine" +ARG SENSU_GO_ASSET_VERSION="2.7.0" +ARG PLUGINS="check_http" + +ADD create-sensu-asset /usr/bin/create-sensu-asset + +WORKDIR / + +RUN apk --update add bash coreutils libintl curl gcc g++ make openssl-dev net-snmp-tools linux-headers procps && \ + curl -s -L -O https://www.monitoring-plugins.org/download/monitoring-plugins-2.3.1.tar.gz && \ + tar xzf monitoring-plugins-2.3.1.tar.gz && \ + cd monitoring-plugins-2.3.1 && \ + ./configure --prefix=/usr --libexecdir=/usr/lib/monitoring-plugins && \ + make && \ + make install + +WORKDIR /usr/lib/monitoring-plugins/ + +RUN create-sensu-asset -a $SENSU_GO_ASSET_NAME -b $PLUGINS -v $SENSU_GO_ASSET_VERSION -o / diff --git a/Dockerfile.amazon1 b/old/Dockerfile.amazon1 similarity index 100% rename from Dockerfile.amazon1 rename to old/Dockerfile.amazon1 diff --git a/Dockerfile.amazon2 b/old/Dockerfile.amazon2 similarity index 100% rename from Dockerfile.amazon2 rename to old/Dockerfile.amazon2 diff --git a/old/Dockerfile.centos6 b/old/Dockerfile.centos6 new file mode 100644 index 0000000..9b25031 --- /dev/null +++ b/old/Dockerfile.centos6 @@ -0,0 +1,24 @@ +FROM centos:6 as builder + +ARG SENSU_GO_ASSET_NAME="monitoring-plugins-centos6" +ARG SENSU_GO_ASSET_VERSION="2.7.0" +ARG PLUGINS="check_http" + +ADD create-sensu-asset /usr/bin/create-sensu-asset + +WORKDIR /usr/lib64/nagios/plugins/ + +WORKDIR / + +RUN curl https://www.getpagespeed.com/files/centos6-eol.repo --output /etc/yum.repos.d/CentOS-Base.repo +RUN yum groupinstall -y "Development Tools" && yum install -y curl expat-devel openssl openssl-devel net-snmp-utils bind-utils && \ + curl -s -L -O https://www.monitoring-plugins.org/download/monitoring-plugins-2.3.1.tar.gz && \ + tar xzf monitoring-plugins-2.3.1.tar.gz && \ + cd monitoring-plugins-2.3.1 && \ + ./configure --prefix=/usr --libexecdir=/usr/lib/monitoring-plugins && \ + make && \ + make install + +WORKDIR /usr/lib/monitoring-plugins/ + +RUN create-sensu-asset -a $SENSU_GO_ASSET_NAME -b $PLUGINS -v $SENSU_GO_ASSET_VERSION -o / diff --git a/Dockerfile.centos7 b/old/Dockerfile.centos7 similarity index 100% rename from Dockerfile.centos7 rename to old/Dockerfile.centos7 diff --git a/Dockerfile.centos8 b/old/Dockerfile.centos8 similarity index 100% rename from Dockerfile.centos8 rename to old/Dockerfile.centos8 diff --git a/Dockerfile.debian10 b/old/Dockerfile.debian10 similarity index 100% rename from Dockerfile.debian10 rename to old/Dockerfile.debian10 diff --git a/Dockerfile.debian11 b/old/Dockerfile.debian11 similarity index 100% rename from Dockerfile.debian11 rename to old/Dockerfile.debian11 diff --git a/old/Dockerfile.debian8 b/old/Dockerfile.debian8 new file mode 100644 index 0000000..487b7c5 --- /dev/null +++ b/old/Dockerfile.debian8 @@ -0,0 +1,23 @@ +FROM debian:jessie as builder + +ARG SENSU_GO_ASSET_NAME="monitoring-plugins-debian8" +ARG SENSU_GO_ASSET_VERSION="2.7.0" +ARG PLUGINS="check_http" + +ADD create-sensu-asset /usr/bin/create-sensu-asset + +WORKDIR / + +RUN apt-get update +RUN apt-get install -y curl +RUN curl -k -s -L -O https://www.monitoring-plugins.org/download/monitoring-plugins-2.3.1.tar.gz +RUN apt-get install -y build-essential curl libexpat1-dev openssl libssl-dev libz-dev snmp dnsutils && \ + tar xzf monitoring-plugins-2.3.1.tar.gz && \ + cd monitoring-plugins-2.3.1 && \ + ./configure --prefix=/usr --libexecdir=/usr/lib/monitoring-plugins && \ + make && \ + make install + +WORKDIR /usr/lib/monitoring-plugins/ + +RUN create-sensu-asset -a $SENSU_GO_ASSET_NAME -b $PLUGINS -v $SENSU_GO_ASSET_VERSION -o / diff --git a/Dockerfile.debian9 b/old/Dockerfile.debian9 similarity index 100% rename from Dockerfile.debian9 rename to old/Dockerfile.debian9 diff --git a/Dockerfile.ubuntu1404 b/old/Dockerfile.ubuntu1404 similarity index 100% rename from Dockerfile.ubuntu1404 rename to old/Dockerfile.ubuntu1404 diff --git a/Dockerfile.ubuntu1604 b/old/Dockerfile.ubuntu1604 similarity index 100% rename from Dockerfile.ubuntu1604 rename to old/Dockerfile.ubuntu1604 diff --git a/Dockerfile.ubuntu1804 b/old/Dockerfile.ubuntu1804 similarity index 100% rename from Dockerfile.ubuntu1804 rename to old/Dockerfile.ubuntu1804 diff --git a/Dockerfile.ubuntu2004 b/old/Dockerfile.ubuntu2004 similarity index 100% rename from Dockerfile.ubuntu2004 rename to old/Dockerfile.ubuntu2004 diff --git a/Dockerfile.ubuntu2204 b/old/Dockerfile.ubuntu2204 similarity index 100% rename from Dockerfile.ubuntu2204 rename to old/Dockerfile.ubuntu2204 diff --git a/build.sh b/old/build.sh similarity index 100% rename from build.sh rename to old/build.sh diff --git a/scripts/build_and_validate.sh b/scripts/build_and_validate.sh new file mode 100755 index 0000000..96fd157 --- /dev/null +++ b/scripts/build_and_validate.sh @@ -0,0 +1,107 @@ +#!/usr/bin/env bash +[ ! -d "./scripts" ] && echo "Directory ./scripts does not exist" && exit 1 +[ ! -d "./tests" ] && echo "Directory ./tests does not exist" && exit 1 +[ ! -d "./builds/enabled" ] && echo "Directory ./builds/enabled does not exist" && exit 1 + +[ ! -f "./.bonsai.yml" ] && echo "File ./.bonsai.yml does not exist" && exit 1 + +if [ -z "$PLUGINS" ] +then + PLUGINS="check_disk,check_dns,check_http,check_load,check_log,check_ntp,check_ntp_peer,check_ntp_time,check_ping,check_procs,check_smtp,check_snmp,check_ssh,check_swap,check_tcp,check_time,check_users,utils.sh" +fi +if [ -z "$ASSET_VERSION" ] +then + ASSET_VERSION=$(git describe --abbrev=0 --tags) +fi +if [ -z "$ASSET_REPONAME" ] +then + ASSET_REPONAME=monitoring-plugins +fi +if [ -z "$PLATFORMS" ] +then + OLD_DIR=$(pwd) + cd builds/enabled + PLATFORMS=$(find . -maxdepth 1 -mindepth 1 -type d) + cd $OLD_DIR +fi +echo "ENABLED PLATFOMRS: $PLATFORMS" + +mkdir -p assets/ +for platform in $PLATFORMS; +do + p=$(basename $platform) + ASSET_FILENAME="${ASSET_REPONAME}-${p}_${ASSET_VERSION}.tar.gz" + [ ! -d "./builds/enabled/${p}" ] && echo "Directory /builds/enabled/${p} does not exist" && exit 1 + if [ -f "./assets/$ASSET_FILENAME" ]; then + echo "File ${ASSET_FILENAME} already exists in assets dir, skippinng this build" + else + echo "Building: $ASSET_FILENAME" + docker build --no-cache --rm --build-arg "PLUGINS=$PLUGINS" --build-arg "SENSU_GO_ASSET_VERSION=$ASSET_VERSION" -t ${ASSET_REPONAME}-${p}:$ASSET_VERSION -f builds/enabled/${p}/Dockerfile . + docker cp -L $(docker create --rm ${ASSET_REPONAME}-${p}:$ASSET_VERSION true):/$ASSET_FILENAME ./assets/ + [ ! -f "./assets/${ASSET_FILENAME}" ] && echo "Error: Asset file ${ASSET_FILENAME} missing from assets directory!" && exit 1 + fi + unset TEST_PLATFORMS + if [ -f "./builds/enabled/${p}/test_platforms" ]; then + TEST_PLATFORMS=$(cat ./builds/enabled/${p}/test_platforms) + fi + unset TEST_PLUGINS + if [ -f "./builds/enabled/${p}/test_plugins" ]; then + TEST_PLUGINS=$(cat ./builds/enabled/${p}/test_plugins) + else + TEST_PLUGINS=${PLUGINS} + fi + if [ -z "$TEST_PLATFORMS" ] + then + echo -e "\nSkipping platform tests: TEST_PLATFORMS empty" + else + echo -e "\nPerforming Cross platform tests\n" + test_arr=($TEST_PLATFORMS) + mkdir -p ./dist/${p} + cd ./dist/${p} + tar xzf $OLD_DIR/assets/$ASSET_FILENAME + cd $OLD_DIR + for test_platform in "${test_arr[@]}"; do + docker run -e platform=${p} -e test_platform=${test_platform} -e plugins=${TEST_PLUGINS} -e asset_filename=${ASSET_FILENAME} -v "$PWD/tests/:/tests" -v "$PWD/scripts/:/scripts" -v "$PWD//dist/${p}:/build" ${test_platform} /scripts/test.sh + retval=$? + if [ $retval -ne 0 ]; then + echo "!!! Error testing ${asset_filename} on ${test_platform}" + exit $retval + fi + done + fi + +done + +echo -e "\nDone Building, ./assets directory contains:" +find ./assets/ -maxdepth 1 -mindepth 1 -type f + +echo -e "\nGenerating checksum file" +cd assets/ +CHECKSUMS_FILENAME="${ASSET_REPONAME}_${ASSET_VERSION}_sha512-checksums.txt" +if [[ $(which sha512sum) ]]; then + sha512sum ./*.tar.gz > $CHECKSUMS_FILENAME; +elif [[ $(which shasum) ]]; then + shasum -a 512 *.tar.gz > $CHECKSUMS_FILENAME; +fi; +cd $OLD_DIR + +echo -e "\nValidating .bonsai.yml asset references" +## Lets validate .bonsai.yml +files=$(grep asset_filename .bonsai.yml | awk -F '"' '{print $2}') +for f in $files +do + filename=${f/'#{version}'/${ASSET_VERSION}} +[ ! -f "./assets/${filename}" ] && echo "Error: bonsai asset_filename: ${filename} missing from assets directory!" && exit 1 +done +files=$(grep sha_file .bonsai.yml | awk -F '"' '{print $2}') +for f in $files +do + filename=${f/'#{version}'/${ASSET_VERSION}} + filename=${filename/'#{repo}'/${ASSET_REPONAME}} + [ ! -f "./assets/${filename}" ] && echo "Error: bonsai sha_file: ${filename} missing from assets directory!" && exit 1 +done + +echo -e "\nDone Validating .bonsai.yml asset references" + + + diff --git a/scripts/test.sh b/scripts/test.sh new file mode 100755 index 0000000..131c716 --- /dev/null +++ b/scripts/test.sh @@ -0,0 +1,30 @@ +#!/bin/bash +echo " Testing Parameters:" +echo " Asset Build: ${platform}" +echo " Target Platform: ${test_platform}" +echo " Asset Tarball: ${asset_filename}" +echo " Plugin Tests: ${plugins}" +#tests=${plugins//hmm/h } +if [ -z "$asset_filename" ]; then + echo "Asset is empty" + exit 1 +fi +#mkdir -p /build +#cd /build +#tar xzf /dist/$asset_filename +export LD_LIBRARY_PATH="/build/lib:$LD_LIBRARY_PATH" +export PATH="/build/bin/:$PATH" +while IFS=',' read -ra tests; do + for t in "${tests[@]}"; do + echo " Running: /tests/test_${t}.sh" + /tests/test_${t}.sh + retval=$? + if [ $retval -ne 0 ]; then + echo "!!! Test error: test_${t}.sh" + exit $retval + fi + + done +done <<< "$plugins" + + diff --git a/tests/test_check_disk.sh b/tests/test_check_disk.sh new file mode 100755 index 0000000..65fd94f --- /dev/null +++ b/tests/test_check_disk.sh @@ -0,0 +1,6 @@ +#/bin/sh +check_disk -w 0 -c 0 -e -l > /dev/null +retval=$? +exit $retval + + diff --git a/tests/test_check_dns.sh b/tests/test_check_dns.sh new file mode 100755 index 0000000..430a6bf --- /dev/null +++ b/tests/test_check_dns.sh @@ -0,0 +1,9 @@ +#/bin/sh +check_dns --help >> /dev/null +retval=$? +if [[ $retval -eq 3 ]]; then + exit 0 +fi +exit $retval + + diff --git a/tests/test_check_http.sh b/tests/test_check_http.sh new file mode 100755 index 0000000..bf0445f --- /dev/null +++ b/tests/test_check_http.sh @@ -0,0 +1,6 @@ +#/bin/sh +check_http -w 5 -c 10 -H www.sensu.io > /dev/null +retval=$? +exit $retval + + diff --git a/tests/test_check_load.sh b/tests/test_check_load.sh new file mode 100755 index 0000000..aa8a813 --- /dev/null +++ b/tests/test_check_load.sh @@ -0,0 +1,9 @@ +#/bin/sh +check_load -w 100,200,300 -c 400,500,600 --help >> /dev/null +retval=$? +if [[ $retval -eq 3 ]]; then + exit 0 +fi +exit $retval + + diff --git a/tests/test_check_log.sh b/tests/test_check_log.sh new file mode 100755 index 0000000..11f09a3 --- /dev/null +++ b/tests/test_check_log.sh @@ -0,0 +1,22 @@ +#/bin/sh +echo "This is a test of the emergency broadcast system" > /test_log.txt +check_log -F /test_log.txt -O /old_test_log.txt -q "This is a test" > stdout.txt 2>stderr.txt + +retval=$? + +error=$(cat stderr.txt) +if [ $retval -ne 0 ] +then + cat stdout.txt + +fi +if [ ! -z "$error" ] +then + echo "check_log stderr is NOT empty" + echo $error + if [ "$error" = "/build/bin/check_log: line 191: diff: command not found" ]; then + exit 0 + fi + exit 1 +fi +exit $retval diff --git a/tests/test_check_ntp.sh b/tests/test_check_ntp.sh new file mode 100755 index 0000000..97fd11c --- /dev/null +++ b/tests/test_check_ntp.sh @@ -0,0 +1,9 @@ +#/bin/sh +check_ntp -H pool.ntp.org -w 10 -c 20 >> /dev/null +retval=$? +if [[ $retval -eq 3 ]]; then + exit 0 +fi +exit $retval + + diff --git a/tests/test_check_ntp_peer.sh b/tests/test_check_ntp_peer.sh new file mode 100755 index 0000000..f92b38e --- /dev/null +++ b/tests/test_check_ntp_peer.sh @@ -0,0 +1,17 @@ +#/bin/sh +check_ntp_peer -H pool.ntp.org -w 10 -c 20 -q > stdout.txt +retval=$? +error=$(cat stdout.txt) +if [[ $retval -eq 0 ]]; then + exit 0 +fi +if [[ $retval -eq 3 ]]; then + exit 0 +fi +if [ "$error" = "CRITICAL - Socket timeout after 10 seconds" ]; then + exit 0 +fi +echo $error +exit $retval + + diff --git a/tests/test_check_ntp_time.sh b/tests/test_check_ntp_time.sh new file mode 100755 index 0000000..96752b6 --- /dev/null +++ b/tests/test_check_ntp_time.sh @@ -0,0 +1,9 @@ +#/bin/sh +check_ntp_time -H pool.ntp.org -w 10 -c 20 >> /dev/null +retval=$? +if [[ $retval -eq 3 ]]; then + exit 0 +fi +exit $retval + + diff --git a/tests/test_check_ping.sh b/tests/test_check_ping.sh new file mode 100755 index 0000000..a954b65 --- /dev/null +++ b/tests/test_check_ping.sh @@ -0,0 +1,9 @@ +#/bin/sh +check_ping -H localhost -w 1,100% -c 2,100% -p 1 > /dev/null +retval=$? +if [[ $retval -eq 3 ]]; then + exit 0 +fi +exit $retval + + diff --git a/tests/test_check_procs.sh b/tests/test_check_procs.sh new file mode 100755 index 0000000..bdeffb1 --- /dev/null +++ b/tests/test_check_procs.sh @@ -0,0 +1,9 @@ +#/bin/sh +check_procs > /dev/null +retval=$? +if [[ $retval -eq 3 ]]; then + exit 0 +fi +exit $retval + + diff --git a/tests/test_check_smtp.sh b/tests/test_check_smtp.sh new file mode 100755 index 0000000..8902181 --- /dev/null +++ b/tests/test_check_smtp.sh @@ -0,0 +1,9 @@ +#/bin/sh +check_smtp -H smtp.gmail.com > /dev/null +retval=$? +if [[ $retval -eq 3 ]]; then + exit 0 +fi +exit $retval + + diff --git a/tests/test_check_snmp.sh b/tests/test_check_snmp.sh new file mode 100755 index 0000000..c66b618 --- /dev/null +++ b/tests/test_check_snmp.sh @@ -0,0 +1,9 @@ +#/bin/sh +check_snmp -H snmp.live.gambitcommunications.com -o sysContact.0 > /dev/null +retval=$? +if [[ $retval -eq 3 ]]; then + exit 0 +fi +exit $retval + + diff --git a/tests/test_check_ssh.sh b/tests/test_check_ssh.sh new file mode 100755 index 0000000..2a4ce2e --- /dev/null +++ b/tests/test_check_ssh.sh @@ -0,0 +1,9 @@ +#/bin/sh +check_ssh --help > /dev/null +retval=$? +if [[ $retval -eq 3 ]]; then + exit 0 +fi +exit $retval + + diff --git a/tests/test_check_swap.sh b/tests/test_check_swap.sh new file mode 100755 index 0000000..aa15d10 --- /dev/null +++ b/tests/test_check_swap.sh @@ -0,0 +1,8 @@ +#/bin/sh +check_swap -w 1 -c 1 > /dev/null +if [[ $retval -eq 3 ]]; then + exit 0 +fi +exit $retval + + diff --git a/tests/test_check_tcp.sh b/tests/test_check_tcp.sh new file mode 100755 index 0000000..f3ccfac --- /dev/null +++ b/tests/test_check_tcp.sh @@ -0,0 +1,9 @@ +#/bin/sh +check_tcp -H www.sensu.io -p 80 > /dev/null +retval=$? +if [[ $retval -eq 3 ]]; then + exit 0 +fi +exit $retval + + diff --git a/tests/test_check_time.sh b/tests/test_check_time.sh new file mode 100755 index 0000000..a9b3dc4 --- /dev/null +++ b/tests/test_check_time.sh @@ -0,0 +1,9 @@ +#/bin/sh +check_time -H Ntp-wwv.nist.gov > /dev/null +retval=$? +if [[ $retval -eq 3 ]]; then + exit 0 +fi +exit $retval + + diff --git a/tests/test_check_users.sh b/tests/test_check_users.sh new file mode 100755 index 0000000..df14c0f --- /dev/null +++ b/tests/test_check_users.sh @@ -0,0 +1,9 @@ +#/bin/sh +check_users -w 1000 -c 10000 > /dev/null +retval=$? +if [[ $retval -eq 3 ]]; then + exit 0 +fi +exit $retval + + diff --git a/tests/test_utils.sh.sh b/tests/test_utils.sh.sh new file mode 100755 index 0000000..4120559 --- /dev/null +++ b/tests/test_utils.sh.sh @@ -0,0 +1,10 @@ +#/bin/sh +source utils.sh +check_range 1 2:8 +retval=$? +if [[ $retval -eq 3 ]]; then + exit 0 +fi +exit $retval + + diff --git a/travis-build.sh b/travis-build.sh deleted file mode 100755 index 5a71780..0000000 --- a/travis-build.sh +++ /dev/null @@ -1,61 +0,0 @@ -#!/usr/bin/env bash -## -# Adapted from sensu/sensu-go-bonsai-asset repo -## - -# Hardwiring repo-name for now, untile the Dockerfile logic is abstracted/tested to use name as passed to docker as build arg -REPO_NAME="monitoring-plugins" - -export PLUGINS="check_disk,check_dns,check_http,check_load,check_log,check_ntp,check_ntp_peer,check_ntp_time,check_ping,check_procs,check_smtp,check_snmp,check_ssh,check_swap,check_tcp,check_time,check_users,utils.sh" - -[[ -z "$WDIR" ]] && { echo "WDIR is empty using bonsai/" ; WDIR="bonsai/"; } - -## -# TravisCI specific asset build script. -# Uses several TravisCI specific environment variables -## -#[[ -z "$1" ]] && { echo "Parameter 1, REPO_NAME is empty" ; exit 1; } -[[ -z "$GITHUB_TOKEN" ]] && { echo "GITHUB_TOKEN is empty, upload disabled" ; } -[[ -z "$TRAVIS_REPO_SLUG" ]] && { echo "TRAVIS_REPO_SLUG is empty"; exit 1; } -if [[ -z "$1" ]]; then - echo "Parameter 1, PLATFORMS is empty, using default set" ; platforms=( alpine alpine3.8 debian8 debian9 debian10 debian11 centos8 centos7 centos6 amazon1 amazon2 ubuntu1404 ubuntu1604 ubuntu1804 ubuntu2004 ubuntu2204 ); -else - IFS=', ' read -r -a platforms <<< "$1" -fi -TAG=$TRAVIS_TAG -CURRENT_COMMIT=$(git rev-parse HEAD) -[[ -z "$TAG" ]] && { echo "TRAVIS_TAG is empty" ; TAG="0.0.1"; } -[[ -z "$TRAVIS_COMMIT" ]] && { echo "TRAVIS_COMMIT is empty, using current commit" ; TRAVIS_COMMIT=$CURRENT_COMMIT; } -echo $REPO_NAME $TRAVIS_REPO_SLUG $TAG $TRAVIS_COMMIT - -mkdir dist -GIT_REPO="https://github.com/${TRAVIS_REPO_SLUG}.git" -GIT_REF=${TRAVIS_COMMIT} - -echo "Platforms: ${platforms[@]}" - -if [ -d dist ]; then - for platform in "${platforms[@]}" - do - if [ -f "Dockerfile.${platform}" ]; then - export SENSU_GO_ASSET_FILENAME="${REPO_NAME}-${platform}_${TAG}_linux_amd64.tar.gz" - echo "Building for Platform: $platform using Dockfile.${platform} ${SENSU_GO_ASSET_FILENAME}" - docker build --no-cache --rm --build-arg "PLUGINS=$PLUGINS" --build-arg "SENSU_GO_ASSET_VERSION=${TAG}" -t ${REPO_NAME}-${platform}:$TAG -f Dockerfile.${platform} . - docker cp -L $(docker create --rm ${REPO_NAME}-${platform}:${TAG} true):/$SENSU_GO_ASSET_FILENAME ./dist/ - if [ -z ${FULL_PRUNE+x} ]; then - echo "FULL_PRUNE unset, skipping docker prune" - else - docker system prune -a -f - fi - else - echo "Skipping for Platform: $platform missing Dockfile.${platform}" - fi - done -else - echo "error dist directory is missing" -fi - - - - - diff --git a/travis-github-upload.sh b/travis-github-upload.sh deleted file mode 100755 index 749b3b0..0000000 --- a/travis-github-upload.sh +++ /dev/null @@ -1,80 +0,0 @@ -#!/usr/bin/env bash -## -# Adapted from sensu/sensu-go-bonsai-asset repo -## - -[[ -z "$WDIR" ]] && { echo "WDIR is empty using bonsai/" ; WDIR="bonsai/"; } - -## -# TravisCI specific asset build script. -# Uses several TravisCI specific environment variables -## -[[ -z "$GITHUB_TOKEN" ]] && { echo "GITHUB_TOKEN is empty, upload disabled" ; } -[[ -z "$TRAVIS_REPO_SLUG" ]] && { echo "TRAVIS_REPO_SLUG is empty"; exit 1; } -TAG=$TRAVIS_TAG -CURRENT_COMMIT=$(git rev-parse HEAD) -[[ -z "$TAG" ]] && { echo "TRAVIS_TAG is empty" ; TAG="0.0.1"; } -[[ -z "$TRAVIS_COMMIT" ]] && { echo "TRAVIS_COMMIT is empty, using current commit" ; TRAVIS_COMMIT=$CURRENT_COMMIT; } - -GIT_REPO="https://github.com/${TRAVIS_REPO_SLUG}.git" -GIT_REF=${TRAVIS_COMMIT} - -if [ -d dist ]; then - # Generate the sha512sum for all the assets - files=$( ls dist/*.tar.gz ) - echo $files - for filename in $files; do - if [[ "$TRAVIS_TAG" ]]; then - if [[ "$GITHUB_TOKEN" ]]; then - if [[ "$TRAVIS_REPO_SLUG" ]]; then - echo "upload $filename" - ${WDIR}/github-release-upload.sh github_api_token=$GITHUB_TOKEN repo_slug="$TRAVIS_REPO_SLUG" tag="${TRAVIS_TAG}" filename="$filename" - else - echo "TRAVIS_REPO_SLUG unset, skipping upload of $filename" - fi - else - echo "GITUB_TOKEN unset, skipping upload of $filename" - fi - fi - done - file=$(basename "${files[0]}") - - # JDS Commenting out the automaatic package logic here for now - #IFS=_ read -r package leftover <<< "$file" - #unset leftover - package="monitoring-plugins" - if [ -n "$package" ]; then - echo "Generating sha512sum for ${package}" - cd dist || exit - sha512_file="${package}_${TAG}_sha512-checksums.txt" - #echo "${sha512_file}" > sha512_file - echo "sha512_file: ${sha512_file}" - sha512sum ./*.tar.gz > "${sha512_file}" - echo "" - cat "${sha512_file}" - cd .. - if [[ "$TRAVIS_TAG" ]]; then - if [[ "$GITHUB_TOKEN" ]]; then - echo "upload ${sha512_file}" - ${WDIR}/github-release-upload.sh github_api_token=$GITHUB_TOKEN repo_slug="$TRAVIS_REPO_SLUG" tag="${TRAVIS_TAG}" filename="dist/${sha512_file}" - else - echo "GITUB_TOKEN unset, skipping upload of ${sha512_file}" - fi - fi - fi - if [[ "$TRAVIS_TAG" ]]; then - if [[ "$GITHUB_TOKEN" ]]; then - if [[ "$TRAVIS_REPO_SLUG" ]]; then - #Generate github release edit event - ${WDIR}/github-release-event.sh github_api_token=$GITHUB_TOKEN repo_slug="$TRAVIS_REPO_SLUG" tag="${TRAVIS_TAG}" - fi - fi - fi -else - echo "error dist directory is missing" -fi - - - - -