This commit is contained in:
52
.gitea/workflows/build-container.yaml
Normal file
52
.gitea/workflows/build-container.yaml
Normal file
@@ -0,0 +1,52 @@
|
||||
name: release-tag
|
||||
|
||||
on:
|
||||
push
|
||||
|
||||
jobs:
|
||||
release-image:
|
||||
runs-on: ubuntu-latest
|
||||
container:
|
||||
image: catthehacker/ubuntu:act-latest
|
||||
env:
|
||||
DOCKER_ORG: angoosh
|
||||
DOCKER_LATEST: latest
|
||||
RUNNER_TOOL_CACHE: /toolcache
|
||||
steps:
|
||||
- name: Checkout
|
||||
uses: actions/checkout@v3
|
||||
|
||||
- name: Set up QEMU
|
||||
uses: docker/setup-qemu-action@v2
|
||||
|
||||
- name: Set up Docker BuildX
|
||||
uses: docker/setup-buildx-action@v2
|
||||
with:
|
||||
config-inline: |
|
||||
[registry."gitea.angoosh.com"]
|
||||
#http = true
|
||||
#insecure = true
|
||||
|
||||
- name: Login to DockerHub
|
||||
uses: docker/login-action@v2
|
||||
with:
|
||||
registry: https://gitea.angoosh.com
|
||||
username: ${{ secrets.PKG_REG_USER }}
|
||||
password: ${{ secrets.PKG_REG_PASS }}
|
||||
|
||||
- name: Get Meta
|
||||
id: meta
|
||||
run: |
|
||||
echo REPO_NAME=$(echo ${GITHUB_REPOSITORY} | awk -F"/" '{print $2}') >> $GITHUB_OUTPUT
|
||||
echo REPO_VERSION=$(git describe --tags --always | sed 's/^v//') >> $GITHUB_OUTPUT
|
||||
|
||||
- name: Build and push
|
||||
uses: docker/build-push-action@v4
|
||||
with:
|
||||
context: .
|
||||
file: ./Dockerfile
|
||||
platforms: |
|
||||
linux/amd64
|
||||
push: true
|
||||
tags: |
|
||||
gitea.angoosh.com/${{ env.DOCKER_ORG }}/${{ steps.meta.outputs.REPO_NAME }}:${{ env.DOCKER_LATEST }}
|
||||
6
Dockerfile
Normal file
6
Dockerfile
Normal file
@@ -0,0 +1,6 @@
|
||||
FROM python:3-alpine
|
||||
ADD requirements.txt /
|
||||
RUN pip install -r requirements.txt
|
||||
ADD main.py /
|
||||
EXPOSE 8000
|
||||
CMD [ "python", "./main.py" ]
|
||||
@@ -1,3 +1,7 @@
|
||||
# mktxp-extension
|
||||
|
||||
Extends mktxp with additional features.
|
||||
|
||||
## Aditional features
|
||||
1. Wireguard
|
||||
2. Mangle
|
||||
|
||||
80
main.py
Normal file
80
main.py
Normal file
@@ -0,0 +1,80 @@
|
||||
import routeros_api
|
||||
from prometheus_client import start_http_server, Gauge
|
||||
import time
|
||||
import re
|
||||
import os
|
||||
|
||||
APP_NAME = 'mktxp-extension'
|
||||
RTR_ADDRESS = os.environ.get('RTR_ADDRESS')
|
||||
RTR_USER = os.environ.get('RTR_USER')
|
||||
RTR_PASS = os.environ.get('RTR_PASS')
|
||||
|
||||
gauge_wg_rx = Gauge(APP_NAME+'_wireguard_rx', 'Rx amount on peer', ['peer','interface'])
|
||||
gauge_wg_tx = Gauge(APP_NAME+'_wireguard_tx', 'Tx amount on peer', ['peer','interface'])
|
||||
gauge_wg_handshake = Gauge(APP_NAME+'_wireguard_handshake', 'Last peer handshake', ['peer','interface'])
|
||||
gauge_wg_active = Gauge(APP_NAME+'_wireguard_active', 'If peer is active, is set to inactive after 5 minutes of last connection', ['peer','interface'])
|
||||
gauge_mangle_rx = Gauge(APP_NAME+'_manle_rx', 'Rx amount on rule', ['comment'])
|
||||
gauge_mangle_tx = Gauge(APP_NAME+'_mangle_tx', 'Tx amount on rule', ['comment'])
|
||||
|
||||
connection = routeros_api.RouterOsApiPool(RTR_ADDRESS, username=RTR_USER, password=RTR_PASS, plaintext_login=True)
|
||||
api = connection.get_api()
|
||||
|
||||
def get_wg():
|
||||
|
||||
list = api.get_resource('/interface/wireguard/peers')
|
||||
peers = list.get()
|
||||
for peer in peers:
|
||||
seconds = 0
|
||||
|
||||
gauge_wg_rx.labels(peer=peer['name'], interface=peer['interface']).set(int(peer['rx']))
|
||||
gauge_wg_tx.labels(peer=peer['name'], interface=peer['interface']).set(int(peer['tx']))
|
||||
lasthandshake = ''
|
||||
try:
|
||||
lasthandshake = peer['last-handshake']
|
||||
|
||||
tm = re.split(r'[dhms]',lasthandshake)
|
||||
tm_rev = []
|
||||
multiply = []
|
||||
for i in range(0,len(tm)-1):
|
||||
tm_rev.append(tm[len(tm)-2-i])
|
||||
if 's' in lasthandshake:
|
||||
multiply.append(1)
|
||||
if 'm' in lasthandshake:
|
||||
multiply.append(60)
|
||||
if 'h' in lasthandshake:
|
||||
multiply.append(3600)
|
||||
if 'd' in lasthandshake:
|
||||
multiply.append(86400)
|
||||
|
||||
for i in range(0, len(tm_rev)):
|
||||
seconds += int(tm_rev[i]) * multiply[i]
|
||||
|
||||
except:
|
||||
seconds = -1
|
||||
gauge_wg_handshake.labels(peer=peer['name'], interface=peer['interface']).set(seconds)
|
||||
if (seconds == -1) or (seconds > 300):
|
||||
gauge_wg_active.labels(peer=peer['name'], interface=peer['interface']).set(0)
|
||||
else:
|
||||
gauge_wg_active.labels(peer=peer['name'], interface=peer['interface']).set(1)
|
||||
|
||||
def get_mangle():
|
||||
|
||||
list = api.get_resource('/ip/firewall/mangle')
|
||||
rules = list.get()
|
||||
for rule in rules:
|
||||
seconds = 0
|
||||
if "Download" in rule['comment']:
|
||||
gauge_mangle_rx.labels(comment=rule['comment']).set(int(rule['bytes']))
|
||||
elif "Upload" in rule['comment']:
|
||||
gauge_mangle_tx.labels(comment=rule['comment']).set(int(rule['bytes']))
|
||||
else:
|
||||
pass
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
start_http_server(8000)
|
||||
|
||||
while True:
|
||||
get_wg()
|
||||
get_mangle()
|
||||
time.sleep(5)
|
||||
3
requirements.txt
Normal file
3
requirements.txt
Normal file
@@ -0,0 +1,3 @@
|
||||
regex
|
||||
prometheus_client
|
||||
routeros_api
|
||||
Reference in New Issue
Block a user