initial commit
This commit is contained in:
commit
1d2c1a17aa
29
.gitea/workflows/check-build.yml
Normal file
29
.gitea/workflows/check-build.yml
Normal file
@ -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
|
41
.gitea/workflows/push-build.yml
Normal file
41
.gitea/workflows/push-build.yml
Normal file
@ -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
|
11
Dockerfile
Normal file
11
Dockerfile
Normal file
@ -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"]
|
10
docker-compose.yml
Normal file
10
docker-compose.yml
Normal file
@ -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"
|
31
logpingresult.py
Normal file
31
logpingresult.py
Normal file
@ -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)
|
5
requirements.txt
Normal file
5
requirements.txt
Normal file
@ -0,0 +1,5 @@
|
|||||||
|
boto==2.49.0
|
||||||
|
boto3==1.26.27
|
||||||
|
botocore==1.29.27
|
||||||
|
requests==2.28.1
|
||||||
|
tabulate==0.8.9
|
Loading…
x
Reference in New Issue
Block a user