commit 1d2c1a17aa84d4c32bfa888ee17a8a2a8395a2d7 Author: Dan Hamik Date: Tue Nov 26 12:27:27 2024 -0600 initial commit diff --git a/.gitea/workflows/check-build.yml b/.gitea/workflows/check-build.yml new file mode 100644 index 0000000..0135fe7 --- /dev/null +++ b/.gitea/workflows/check-build.yml @@ -0,0 +1,29 @@ +Name: Commit Checks +run-name: ${{ gitea.actor }} +on: + push: + branches: + - "**" + - "!main" + +jobs: + Plan: + runs-on: ubuntu-latest + defaults: + run: + working-directory: ./ + steps: + - uses: actions/checkout@v4 + with: + fetch-depth: 0 +# + - name: List Contents + id: ls + run: ls -al + + + - name: Deploy + run: | + echo "${{ secrets.GITEASECRET_TOKEN }}" | docker login git.hamik.net -u paradizelost --password-stdin + docker build -t git.hamik.net/paradizelost/pingtest:dev . + docker push git.hamik.net/paradizelost/pingtest:dev \ No newline at end of file diff --git a/.gitea/workflows/push-build.yml b/.gitea/workflows/push-build.yml new file mode 100644 index 0000000..84ca5d1 --- /dev/null +++ b/.gitea/workflows/push-build.yml @@ -0,0 +1,41 @@ +Name: Container Build Push +run-name: ${{ gitea.actor }} +on: + pull_request: + types: [closed] + +jobs: + Plan: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + with: + fetch-depth: 0 + + - name: List Contents + id: ls + run: ls -al + + - name: Deploy + run: | + echo "${{ secrets.GITEASECRET_TOKEN }}" | docker login git.hamik.net -u paradizelost --password-stdin + docker build -t git.hamik.net/paradizelost/pingtest:latest . + docker push git.hamik.net/paradizelost/pingtest:latest + Deploy: + needs: [Plan] + runs-on: pingtest + defaults: + run: + working-directory: /docker/pingtest + steps: + - name: Destroy Container + id: down + run: docker compose down + + - name: Pull Updates + id: pull + run: docker compose pull + + - name: Start Containers + id: start + run: docker compose up -d \ No newline at end of file diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..811c0f3 --- /dev/null +++ b/Dockerfile @@ -0,0 +1,11 @@ +FROM debian:bullseye-slim +# +RUN apt update && apt install python3 python3-pip -y +COPY logpingresult.py /usr/local/bin/ +COPY requirements.txt / +COPY init.sh / +RUN chmod +x /init.sh +RUN chmod +x /usr/local/bin/logpingresult.py +RUN pip3 install -r /requirements.txt +RUN apt clean +CMD ["/init.sh"] \ No newline at end of file diff --git a/docker-compose.yml b/docker-compose.yml new file mode 100644 index 0000000..4cd5e50 --- /dev/null +++ b/docker-compose.yml @@ -0,0 +1,10 @@ +services: + enphase: + image: git.hamik.net/paradizelost/pingtest:latest + container_name: pingtest + restart: always + environment: + - INFLUX_USER=${INFLUX_USER} + - INFLUX_PASSWORD=${INFLUX_PASSWORD} + - INFLUX_URI=${INFLUX_URI} + - PING_HOSTS="8.8.8.8,10.0.2.1,24.220.0.10,10.2.0.1,192.168.1.25" \ No newline at end of file diff --git a/init.sh b/init.sh new file mode 100644 index 0000000..073ae04 --- /dev/null +++ b/init.sh @@ -0,0 +1,2 @@ +#!/bin/bash +/usr/local/bin/logpingresult.py \ No newline at end of file diff --git a/logpingresult.py b/logpingresult.py new file mode 100644 index 0000000..08492b1 --- /dev/null +++ b/logpingresult.py @@ -0,0 +1,31 @@ +#/usr/bin/python3 +import os +import subprocess as sp +import requests +import time +def addinfluxrecord(ip,pingtime): + data = f"PingTime,IP={ip} value={pingtime}" + print(data) + headers = {'Content-Type': 'application/x-www-form-urlencoded'} + response = requests.post( + influxuri, + data=data, + headers=headers, + auth=(infdbuser,infdbpass), + ) + return response +infdbuser = os.environ["INFLUX_USER"] +infdbpass = os.environ["INFLUX_PASSWORD"] +influxuri = os.environ["INFLUX_URI"] +pingaddresses = os.environ["PING_HOSTS"].split(",") +while(True): + for ip in pingaddresses: + response = sp.getstatusoutput(f"ping -c 1 {ip}") + if(response[0]!=0): + time=2000 + else: + myresp = response[1].split("\n")[1].split(' ')[6].split('=')[1] + + result = addinfluxrecord(ip,myresp) + print(result) + time.sleep(5) \ No newline at end of file diff --git a/requirements.txt b/requirements.txt new file mode 100644 index 0000000..e6593da --- /dev/null +++ b/requirements.txt @@ -0,0 +1,5 @@ +boto==2.49.0 +boto3==1.26.27 +botocore==1.29.27 +requests==2.28.1 +tabulate==0.8.9 \ No newline at end of file