Skip to content

Commit 73e946a

Browse files
authored
v2.4.3 release
1 parent 5b07873 commit 73e946a

File tree

9 files changed

+96
-75
lines changed

9 files changed

+96
-75
lines changed

Dockerfile

Lines changed: 33 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -1,50 +1,52 @@
1-
FROM python:3-slim
1+
# Stage 1: Build environment
2+
FROM python:3.13-slim AS builder
23

34
LABEL maintainer="[email protected]"
45

5-
## setup home folder
6+
# Setup home folder
67
RUN mkdir -p /root/.config/NPMGRAF
78

8-
## install curl gcc for slim image
9-
RUN apt-get update && apt-get install -y \
10-
curl gcc git build-essential\
9+
# Install necessary packages for building
10+
RUN apt-get update && apt-get install -y --no-install-recommends \
11+
gcc git build-essential \
1112
&& rm -rf /var/lib/apt/lists/*
1213

13-
# Clone the grepcidr repository
14-
RUN git clone https://github.com/ryantig/grepcidr.git /opt/grepcidr
15-
16-
# Build and install grepcidr
17-
RUN cd /opt/grepcidr && \
14+
# Clone, build, and install grepcidr
15+
RUN git clone --depth 1 https://github.com/ryantig/grepcidr.git /opt/grepcidr && \
16+
cd /opt/grepcidr && \
1817
make && \
19-
make install
18+
make install && \
19+
rm -rf /opt/grepcidr
2020

21-
# Clean up by removing the source code if not needed
22-
RUN rm -rf /opt/grepcidr
21+
# Install Python packages
22+
COPY requirements.txt /root/.config/NPMGRAF/requirements.txt
23+
RUN pip install --no-cache-dir -r /root/.config/NPMGRAF/requirements.txt
2324

24-
RUN apt-get remove git build-essential -y\
25-
&& rm -rf /var/cache/apk/* \
26-
&& apt-get autoremove -y && apt-get clean
25+
# Stage 2: Runtime environment
26+
FROM python:3.13-slim
2727

28-
COPY requirements.txt /root/.config/NPMGRAF/requirements.txt
29-
RUN pip install -r /root/.config/NPMGRAF/requirements.txt
28+
# Setup home folder
29+
RUN mkdir -p /root/.config/NPMGRAF
3030

31-
## Copy files
32-
COPY Getipinfo.py /root/.config/NPMGRAF/Getipinfo.py
33-
RUN chmod +x /root/.config/NPMGRAF/Getipinfo.py
31+
# Install curl in the final image
32+
RUN apt-get update && apt-get install -y --no-install-recommends \
33+
curl \
34+
&& rm -rf /var/lib/apt/lists/*
3435

35-
COPY Internalipinfo.py /root/.config/NPMGRAF/Internalipinfo.py
36-
RUN chmod +x /root/.config/NPMGRAF/Internalipinfo.py
36+
# Copy the installed grepcidr binary from the builder stage
37+
COPY --from=builder /usr/local/bin/grepcidr /usr/local/bin/grepcidr
3738

38-
COPY sendips.sh /root/.config/NPMGRAF/sendips.sh
39-
RUN chmod +x /root/.config/NPMGRAF/sendips.sh
39+
# Copy installed Python packages from the builder stage
40+
COPY --from=builder /usr/local/lib/python3.13/site-packages /usr/local/lib/python3.13/site-packages
4041

42+
# Copy Python scripts and set permissions
43+
COPY Getipinfo.py /root/.config/NPMGRAF/Getipinfo.py
44+
COPY Internalipinfo.py /root/.config/NPMGRAF/Internalipinfo.py
45+
COPY sendips.sh /root/.config/NPMGRAF/sendips.sh
4146
COPY sendredirectionips.sh /root/.config/NPMGRAF/sendredirectionips.sh
42-
RUN chmod +x /root/.config/NPMGRAF/sendredirectionips.sh
43-
4447
COPY start.sh /root/start.sh
45-
RUN chmod +x /root/start.sh
46-
47-
ENTRYPOINT ["/root/start.sh"]
48-
4948

49+
RUN chmod +x /root/.config/NPMGRAF/*.py /root/start.sh
5050

51+
# Set the entry point
52+
ENTRYPOINT ["/root/start.sh"]

Dockerfile-arm

Lines changed: 13 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -5,41 +5,31 @@ LABEL maintainer="[email protected]"
55
## setup home folder
66
RUN mkdir -p /root/.config/NPMGRAF
77

8-
# Clone the grepcidr repository
9-
RUN git clone https://github.com/ryantig/grepcidr.git /opt/grepcidr
10-
11-
# Build and install grepcidr
12-
RUN cd /opt/grepcidr && \
13-
make && \
14-
make install
15-
16-
# Clean up by removing the source code if not needed
17-
RUN rm -rf /opt/grepcidr
8+
# Install git and build-essential, clone the repository, build and install grepcidr, then clean up
9+
RUN git clone https://github.com/ryantig/grepcidr.git /opt/grepcidr \
10+
&& cd /opt/grepcidr && make && make install \
11+
&& rm -rf /opt/grepcidr \
12+
&& apt-get remove --purge -y git build-essential \
13+
&& apt-get autoremove -y \
14+
&& apt-get clean \
15+
&& rm -rf /var/lib/apt/lists/*
1816

1917
RUN apt-get remove git build-essential -y\
2018
&& rm -rf /var/cache/apk/* \
2119
&& apt-get autoremove -y && apt-get clean
2220

2321
COPY requirements.txt /root/.config/NPMGRAF/requirements.txt
24-
RUN pip install -r /root/.config/NPMGRAF/requirements.txt
22+
RUN pip install --no-cache-dir -r /root/.config/NPMGRAF/requirements.txt
2523

2624
## Copy files
2725
COPY Getipinfo.py /root/.config/NPMGRAF/Getipinfo.py
28-
RUN chmod +x /root/.config/NPMGRAF/Getipinfo.py
29-
3026
COPY Internalipinfo.py /root/.config/NPMGRAF/Internalipinfo.py
31-
RUN chmod +x /root/.config/NPMGRAF/Internalipinfo.py
32-
3327
COPY sendips.sh /root/.config/NPMGRAF/sendips.sh
34-
RUN chmod +x /root/.config/NPMGRAF/sendips.sh
35-
3628
COPY sendredirectionips.sh /root/.config/NPMGRAF/sendredirectionips.sh
37-
RUN chmod +x /root/.config/NPMGRAF/sendredirectionips.sh
38-
3929
COPY start.sh /root/start.sh
40-
RUN chmod +x /root/start.sh
41-
42-
ENTRYPOINT ["/root/start.sh"]
43-
4430

31+
# Make scripts executable
32+
RUN chmod +x /root/.config/NPMGRAF/*.py /root/.config/NPMGRAF/*.sh /root/start.sh
4533

34+
# Set the entry point
35+
ENTRYPOINT ["/root/start.sh"]

Getipinfo.py

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -54,11 +54,21 @@
5454
Target = str(sys.argv[4])
5555
reader.close()
5656

57-
if asn =='true':
58-
reader = geoip2.database.Reader('/geolite/GeoLite2-ASN.mmdb')
59-
response = reader.asn(str(sys.argv[1]))
60-
Asn = response.autonomous_system_organization
61-
reader.close()
57+
import sys
58+
import geoip2.database
59+
60+
if asn == 'true':
61+
try:
62+
reader = geoip2.database.Reader('/geolite/GeoLite2-ASN.mmdb')
63+
response = reader.asn(str(sys.argv[1]))
64+
Asn = response.autonomous_system_organization
65+
except geoip2.errors.AddressNotFoundError:
66+
Asn = "No ASN associated"
67+
except Exception as e:
68+
Asn = f"An error occurred: {e}"
69+
finally:
70+
reader.close()
71+
6272

6373
# print to log
6474
print (Country)

README.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
# npmGrafStats
22
NginxProxyManager Grafana Statistics.
33

4-
This project analyzes the logs of the Nginx Proxy Manager and exports them to InfluxDB to be used in a Grafana Dashboard.
4+
This project analyzes the logs of the Nginx Proxy Manager and exports them to InfluxDB to be used in a Grafana Dashboard. If you are using npmPlus have a look at the branch: https://github.com/smilebasti/npmGrafStats/tree/npmPlus-main
55

66
npmGrafStats can save the Revers-Proxy and/or the Redirection Logs. Also a exclusion of IP's from for example external montitoring services is possible.
77

@@ -19,7 +19,7 @@ A view of the Grafana Dashboard only within a few hours of running:
1919
![npmGrafStats](https://user-images.githubusercontent.com/60941345/203383131-50b7197e-2e58-4bb1-a7e6-d92e15d3430a.png)
2020

2121
## Newest features
22-
v2.4.2 added cidr notation to the monitoringips.txt (CIDR format a.b.c.d/xx or aa:bb::cc::dd/xx IP range a.b.c.d-e.f.g.h Single IP a.b.c.d or aa:bb:cc::dd).
22+
v2.4.3 optimizations and fixes and add support for npmPlus (see branch https://github.com/smilebasti/npmGrafStats/tree/npmPlus-main)
2323

2424
This project is a modified clone of https://github.com/Festeazy/nginxproxymanagerGraf and independent of https://github.com/jc21/nginx-proxy-manager. Changes to the original project can be found in the [changelog.md](https://github.com/smilebasti/npmGrafStats/blob/main/changelog.md) file.
2525

@@ -38,4 +38,4 @@ A full installation example is available with the [docker-compose.yml](https://g
3838

3939
## Star History
4040

41-
[![Star History Chart](https://api.star-history.com/svg?repos=smilebasti/npmgrafstats&type=Date)](https://star-history.com/#smilebasti/npmgrafstats&Date)
41+
[![Star History Chart](https://api.star-history.com/svg?repos=smilebasti/npmgrafstats&type=Date)](https://star-history.com/#smilebasti/npmgrafstats&Date)

changelog.md

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,19 @@
22

33
### Todo list
44
- Get lenght and device
5-
- grafana more internal panels and plain numbers
5+
- add Status code (see #53 thanks @gitwasi)
6+
- add status code to Grafana
67

78
### Not planned features
89
- maybe analys fallback/default/error logs
910
- grafan 10.1 missle map (route feature only one and not multiple possible)
1011

12+
## v2.4.3
13+
- make dockerfiles multi stage builds
14+
- add seperate Branch of npmPlusGrafStats (main and version)
15+
- fix #47 - handle if no ASN is found
16+
- add concurrent processing
17+
1118
## v2.4.2
1219
- add cidr notation in monitoringips.txt file (see #45 thanks @pitbull)
1320

docker-compose.yml

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
version: '3.8'
21
services:
32
npm:
43
image: 'jc21/nginx-proxy-manager:latest'
@@ -43,10 +42,10 @@ services:
4342
REDIRECTION_LOGS: '<set TRUE or FALSE or ONLY>' # TRUE or FALSE or ONLY
4443
INTERNAL_LOGS: '<set TRUE or FALSE>' # see Github wiki for more information
4544
MONITORING_LOGS: '<set TRUE or FALSE>' # see Github wiki for more information
46-
INFLUX_HOST: '<replace>:8086' # use host IP
45+
INFLUX_HOST: 'http://influxdb:8086' # use host IP if necessary
4746
INFLUX_BUCKET: 'npmgrafstats'
4847
INFLUX_ORG: 'npmgrafstats'
49-
INFLUX_TOKEN: '<replace>' # insert after first run and manual token creation
48+
INFLUX_TOKEN: '<replace>' # REQUIRED! insert after first run and manual token creation
5049
volumes:
5150
- ./data/logs:/logs
5251
- ./geolite:/geolite

sendips.sh

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -24,9 +24,9 @@ fi
2424

2525
# gets all lines including an IP.
2626
# Grep finds the the IP addresses in the access.log
27-
tail -F /logs/proxy-host-*_access.log | grep --line-buffered -E "([0-9]{1,3}[\.]){3}[0-9]{1,3}" | while read line;
27+
process_logfile(){
28+
tail -F "$logfile" | grep --line-buffered -E "([0-9]{1,3}[\.]){3}[0-9]{1,3}" | while read line; do
2829

29-
do
3030
# Domain or subdomain gets found.
3131
targetdomain=`echo $line | grep --line-buffered -m 1 -o -E "([a-z0-9\-]*\.){1,3}?[a-z0-9\-]*\.[A-Za-z]{2,6}" | head -1`
3232

@@ -55,7 +55,7 @@ do
5555
then
5656
python /root/.config/NPMGRAF/Internalipinfo.py "$outsideip" "$targetdomain" "$length" "$targetip" "InternalRProxyIPs" "$measurementtime"
5757
fi
58-
elif $monitorfile && grepcidr -D $outsideip /monitoringips.txt >> /dev/nul
58+
elif [[ $monitorfile ]] && grepcidr -D $outsideip /monitoringips.txt >> /dev/null
5959
then
6060
echo "An excluded monitoring service checked: $targetdomain"
6161
if [ "$MONITORING_LOGS" = "TRUE" ]
@@ -66,4 +66,10 @@ do
6666
python /root/.config/NPMGRAF/Getipinfo.py "$outsideip" "$targetdomain" "$length" "$targetip" "ReverseProxyConnections" "$measurementtime" "$asndb"
6767
fi
6868
done
69-
reboot
69+
}
70+
71+
for logfile in /logs/proxy-host-*_access.log; do
72+
process_logfile "$logfile" &
73+
done
74+
75+
wait

sendredirectionips.sh

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -24,9 +24,9 @@ fi
2424

2525
# gets all lines including an IP.
2626
# Grep finds the the IP addresses in the access.log
27-
tail -F /logs/redirection-host-*_access.log | grep --line-buffered -E "([0-9]{1,3}[\.]){3}[0-9]{1,3}" | while read line;
27+
process_logfile(){
28+
tail -F "$logfile"| grep --line-buffered -E "([0-9]{1,3}[\.]){3}[0-9]{1,3}" | while read line; do
2829

29-
do
3030
# Domain or subdomain gets found.
3131
targetdomain=`echo $line | grep --line-buffered -m 1 -o -E "([a-z0-9\-]*\.){1,3}?[a-z0-9\-]*\.[A-Za-z]{2,6}" | head -1`
3232

@@ -48,7 +48,7 @@ do
4848
then
4949
python /root/.config/NPMGRAF/Internalipinfo.py "$outsideip" "$targetdomain" "$length" "$targetip" "InternalRProxyIPs" "$measurementtime"
5050
fi
51-
elif $monitorfile && grepcidr -D $outsideip /monitoringips.txt >> /dev/null
51+
elif [[ monitorfile ]] && grepcidr -D $outsideip /monitoringips.txt >> /dev/null
5252
then
5353
echo "An excluded monitoring service checked: $targetdomain"
5454
if [ "$MONITORING_LOGS" = "TRUE" ]
@@ -59,4 +59,11 @@ do
5959
python /root/.config/NPMGRAF/Getipinfo.py "$outsideip" "$targetdomain" "0" "redirect" "Redirections" "$measurementtime" "$asndb"
6060
fi
6161
done
62-
reboot
62+
63+
}
64+
65+
for logfile in /logs/redirection-host-*_access.log; do
66+
process_logfile "$logfile" &
67+
done
68+
69+
wait

start.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
#!/bin/bash
2-
echo "npmGrafStats: v2.4.2-pre"
2+
echo "npmGrafStats: v2.4.3"
33
echo "Startup: lets get the logs send them to influx"
44

55

0 commit comments

Comments
 (0)