├── Dockerfile ├── Getipinfo.py ├── Nginx Proxy Manager (Reverse Proxy)-1617242336898.json ├── README.md ├── Screenshot 2021-02-14 142221.png ├── sendips.sh └── start.sh /Dockerfile: -------------------------------------------------------------------------------- 1 | FROM alpine:latest 2 | 3 | #add curl for better handling 4 | RUN apk add --no-cache curl 5 | RUN apk add linux-headers 6 | # Update & Install dependencies 7 | RUN apk add --no-cache --update \ 8 | git \ 9 | bash \ 10 | libffi-dev \ 11 | openssl-dev \ 12 | bzip2-dev \ 13 | zlib-dev \ 14 | readline-dev \ 15 | sqlite-dev \ 16 | build-base 17 | 18 | # Set Python version 19 | ARG PYTHON_VERSION='3.7.0' 20 | RUN export PYTHON_VERSION 21 | # Set pyenv home 22 | ARG PYENV_HOME=/root/.pyenv 23 | RUN export PYENV_HOME 24 | 25 | # Install pyenv, then install python versions 26 | RUN git clone --depth 1 https://github.com/pyenv/pyenv.git $PYENV_HOME && \ 27 | rm -rfv $PYENV_HOME/.git 28 | 29 | ENV PATH $PYENV_HOME/shims:$PYENV_HOME/bin:$PATH 30 | 31 | RUN pyenv install $PYTHON_VERSION 32 | RUN pyenv global $PYTHON_VERSION 33 | RUN pip install --upgrade pip && pyenv rehash 34 | RUN pip install geoip2 35 | RUN pip install influxdb 36 | 37 | # Clean 38 | RUN rm -rf ~/.cache/pip 39 | 40 | # Done python3.7 setup 41 | 42 | ## setup home folder 43 | RUN mkdir -p /root/.config/NPMGRAF 44 | 45 | ENV NPMGRAF_HOME=/root/.config/NPMGRAF 46 | ARG NPMGRAF_HOME=/root/.config/NPMGRAF 47 | RUN export NPMGRAF_HOME 48 | 49 | ## exludeHOMEIps 50 | ENV HOME_IPS="192.168.0.*\|192.168.10.*" 51 | ARG HOME_IPS="192.168.0.*\|192.168.10.*" 52 | 53 | 54 | ## seting up influx connection 55 | ENV INFLUX_USER=admin 56 | ARG INFLUX_USER=admin 57 | 58 | ENV INFLUX_PW=admin 59 | ARG INFLUX_PW=admin 60 | 61 | ENV INFLUX_DB=DB 62 | ARG INFLUX_DB=DB 63 | 64 | ENV INFLUX_HOST=192.168.0.11 65 | ARG INFLUX_HOST=192.168.0.11 66 | 67 | ENV INFLUX_PORT=192.168.0.11 68 | ARG INFLUX_PORT=192.168.0.11 69 | 70 | 71 | 72 | ## Copy files 73 | COPY Getipinfo.py /root/.config/NPMGRAF/Getipinfo.py 74 | RUN chmod +x /root/.config/NPMGRAF/Getipinfo.py 75 | 76 | COPY sendips.sh /root/.config/NPMGRAF/sendips.sh 77 | RUN chmod +x /root/.config/NPMGRAF/sendips.sh 78 | 79 | COPY start.sh /root/start.sh 80 | RUN chmod +x /root/start.sh 81 | 82 | ENTRYPOINT ["/root/start.sh"] 83 | 84 | 85 | 86 | -------------------------------------------------------------------------------- /Getipinfo.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/python3 2 | 3 | import sys 4 | #import geoip2.webservice 5 | print ('*************************************') 6 | print (sys.argv[1]) 7 | 8 | #print str(sys.argv[1]) 9 | import geoip2.database 10 | import socket 11 | 12 | print(socket.gethostname()) 13 | 14 | 15 | 16 | reader = geoip2.database.Reader('/GeoLite2-City.mmdb') 17 | response = reader.city(str(sys.argv[1])) 18 | 19 | Lat = response.location.latitude 20 | ISO = response.country.iso_code 21 | Long = response.location.longitude 22 | State = response.subdivisions.most_specific.name 23 | City = response.city.name 24 | Country = response.country.name 25 | Zip = response.postal.code 26 | IP = str(sys.argv[1]) 27 | Domain = str(sys.argv[2]) 28 | duration = int(sys.argv[3]) 29 | print (Country) 30 | print (State) 31 | print (City) 32 | print (Zip) 33 | print (Long) 34 | print (Lat) 35 | print (ISO) 36 | print (IP) 37 | reader.close() 38 | 39 | 40 | import datetime 41 | from influxdb import InfluxDBClient 42 | 43 | ## get env vars and use 44 | 45 | import os 46 | # influx configuration - edit these 47 | 48 | npmhome = "/root/.config/NPMGRAF" 49 | npmhome = os.getenv('NPMGRAF_HOME') 50 | ifuser = os.getenv('INFLUX_USER') 51 | ifpass = os.getenv('INFLUX_PW') 52 | ifdb = os.getenv('INFLUX_DB') 53 | ifhost = os.getenv('INFLUX_HOST') 54 | ifport = os.getenv('INFLUX_PORT') 55 | 56 | hostname = socket.gethostname() 57 | measurement_name = ("ReverseProxyConnections") 58 | print (measurement_name) 59 | print ('*************************************') 60 | # take a timestamp for this measurement 61 | time = datetime.datetime.utcnow() 62 | 63 | # format the data as a single measurement for influx 64 | body = [ 65 | { 66 | "measurement": measurement_name, 67 | "time": time, 68 | "tags": { 69 | "key": ISO, 70 | "latitude": Lat, 71 | "longitude": Long, 72 | "Domain": Domain, 73 | "City": City, 74 | "State": State, 75 | "name": Country, 76 | "IP": IP 77 | }, 78 | "fields": { 79 | "Domain": Domain, 80 | "latitude": Lat, 81 | "longitude": Long, 82 | "State": State, 83 | "City": City, 84 | "key": ISO, 85 | "IP": IP, 86 | "name": Country, 87 | "duration": duration, 88 | "metric": 1 89 | } 90 | } 91 | ] 92 | 93 | # connect to influx 94 | ifclient = InfluxDBClient(ifhost,ifport,ifuser,ifpass,ifdb) 95 | 96 | # write the measurement 97 | ifclient.write_points(body) 98 | 99 | -------------------------------------------------------------------------------- /Nginx Proxy Manager (Reverse Proxy)-1617242336898.json: -------------------------------------------------------------------------------- 1 | { 2 | "__inputs": [ 3 | { 4 | "name": "DS_INFLUXDB-NGINX-PROXY-MANAGER", 5 | "label": "InfluxDB-nginx-proxy-manager", 6 | "description": "", 7 | "type": "datasource", 8 | "pluginId": "influxdb", 9 | "pluginName": "InfluxDB" 10 | } 11 | ], 12 | "__requires": [ 13 | { 14 | "type": "grafana", 15 | "id": "grafana", 16 | "name": "Grafana", 17 | "version": "7.4.5" 18 | }, 19 | { 20 | "type": "panel", 21 | "id": "grafana-worldmap-panel", 22 | "name": "Worldmap Panel", 23 | "version": "0.3.2" 24 | }, 25 | { 26 | "type": "datasource", 27 | "id": "influxdb", 28 | "name": "InfluxDB", 29 | "version": "1.0.0" 30 | }, 31 | { 32 | "type": "panel", 33 | "id": "table", 34 | "name": "Table", 35 | "version": "" 36 | } 37 | ], 38 | "annotations": { 39 | "list": [ 40 | { 41 | "builtIn": 1, 42 | "datasource": "-- Grafana --", 43 | "enable": true, 44 | "hide": true, 45 | "iconColor": "rgba(0, 211, 255, 1)", 46 | "name": "Annotations & Alerts", 47 | "type": "dashboard" 48 | } 49 | ] 50 | }, 51 | "editable": true, 52 | "gnetId": null, 53 | "graphTooltip": 0, 54 | "id": null, 55 | "links": [], 56 | "panels": [ 57 | { 58 | "circleMaxSize": 30, 59 | "circleMinSize": 2, 60 | "colors": [ 61 | "rgba(245, 54, 54, 0.9)", 62 | "rgba(237, 129, 40, 0.89)", 63 | "rgba(50, 172, 45, 0.97)" 64 | ], 65 | "datasource": "${DS_INFLUXDB-NGINX-PROXY-MANAGER}", 66 | "decimals": 0, 67 | "description": "SELECT count(\"IP\") AS \"counts\" FROM \"ReverseProxyConnections\" WHERE $timeFilter GROUP BY \"latitude\", \"longitude\", \"IP\"", 68 | "esMetric": "Count", 69 | "fieldConfig": { 70 | "defaults": { 71 | "custom": {} 72 | }, 73 | "overrides": [] 74 | }, 75 | "gridPos": { 76 | "h": 18, 77 | "w": 10, 78 | "x": 0, 79 | "y": 0 80 | }, 81 | "hideEmpty": false, 82 | "hideZero": false, 83 | "id": 2, 84 | "initialZoom": "2", 85 | "locationData": "table", 86 | "mapCenter": "custom", 87 | "mapCenterLatitude": "40", 88 | "mapCenterLongitude": "-10", 89 | "maxDataPoints": 1, 90 | "mouseWheelZoom": false, 91 | "pluginVersion": "7.4.5", 92 | "showLegend": true, 93 | "stickyLabels": false, 94 | "tableQueryOptions": { 95 | "geohashField": "geohash", 96 | "labelField": "IP", 97 | "latitudeField": "latitude", 98 | "longitudeField": "longitude", 99 | "metricField": "counts", 100 | "queryType": "coordinates" 101 | }, 102 | "targets": [ 103 | { 104 | "groupBy": [ 105 | { 106 | "params": [ 107 | "latitude" 108 | ], 109 | "type": "tag" 110 | }, 111 | { 112 | "params": [ 113 | "longitude" 114 | ], 115 | "type": "tag" 116 | }, 117 | { 118 | "params": [ 119 | "IP" 120 | ], 121 | "type": "tag" 122 | } 123 | ], 124 | "measurement": "ReverseProxyConnections", 125 | "orderByTime": "ASC", 126 | "policy": "default", 127 | "query": "SELECT count(\"IP\") AS \"counts\" FROM \"ReverseProxyConnections\" WHERE $timeFilter GROUP BY \"latitude\", \"longitude\", \"IP\"", 128 | "rawQuery": false, 129 | "refId": "A", 130 | "resultFormat": "table", 131 | "select": [ 132 | [ 133 | { 134 | "params": [ 135 | "IP" 136 | ], 137 | "type": "field" 138 | }, 139 | { 140 | "params": [], 141 | "type": "count" 142 | }, 143 | { 144 | "params": [ 145 | "counts" 146 | ], 147 | "type": "alias" 148 | } 149 | ] 150 | ], 151 | "tags": [] 152 | } 153 | ], 154 | "thresholds": "0,10", 155 | "timeFrom": null, 156 | "timeShift": null, 157 | "title": "Geo-IP Connections", 158 | "type": "grafana-worldmap-panel", 159 | "unitPlural": "", 160 | "unitSingle": "", 161 | "valueName": "total" 162 | }, 163 | { 164 | "datasource": "${DS_INFLUXDB-NGINX-PROXY-MANAGER}", 165 | "fieldConfig": { 166 | "defaults": { 167 | "color": { 168 | "mode": "thresholds" 169 | }, 170 | "custom": { 171 | "align": null, 172 | "filterable": false 173 | }, 174 | "mappings": [], 175 | "thresholds": { 176 | "mode": "absolute", 177 | "steps": [ 178 | { 179 | "color": "green", 180 | "value": null 181 | }, 182 | { 183 | "color": "red", 184 | "value": 80 185 | } 186 | ] 187 | } 188 | }, 189 | "overrides": [] 190 | }, 191 | "gridPos": { 192 | "h": 18, 193 | "w": 14, 194 | "x": 10, 195 | "y": 0 196 | }, 197 | "id": 4, 198 | "options": { 199 | "showHeader": true, 200 | "sortBy": [ 201 | { 202 | "desc": true, 203 | "displayName": "Time" 204 | } 205 | ] 206 | }, 207 | "pluginVersion": "7.4.5", 208 | "targets": [ 209 | { 210 | "groupBy": [ 211 | { 212 | "params": [ 213 | "IP" 214 | ], 215 | "type": "tag" 216 | } 217 | ], 218 | "measurement": "ReverseProxyConnections", 219 | "orderByTime": "ASC", 220 | "policy": "default", 221 | "query": "SELECT \"IP\" FROM \"ReverseProxyConnections\" WHERE $timeFilter", 222 | "rawQuery": false, 223 | "refId": "A", 224 | "resultFormat": "table", 225 | "select": [ 226 | [ 227 | { 228 | "params": [ 229 | "Domain" 230 | ], 231 | "type": "field" 232 | }, 233 | { 234 | "params": [ 235 | "Domain" 236 | ], 237 | "type": "alias" 238 | } 239 | ], 240 | [ 241 | { 242 | "params": [ 243 | "City" 244 | ], 245 | "type": "field" 246 | } 247 | ], 248 | [ 249 | { 250 | "params": [ 251 | "State" 252 | ], 253 | "type": "field" 254 | } 255 | ] 256 | ], 257 | "tags": [] 258 | } 259 | ], 260 | "title": "Recent Connections", 261 | "type": "table" 262 | } 263 | ], 264 | "refresh": "5s", 265 | "schemaVersion": 27, 266 | "style": "dark", 267 | "tags": [], 268 | "templating": { 269 | "list": [] 270 | }, 271 | "time": { 272 | "from": "now-6h", 273 | "to": "now" 274 | }, 275 | "timepicker": {}, 276 | "timezone": "", 277 | "title": "Nginx Proxy Manager (Reverse Proxy)", 278 | "uid": "t_GiIN_Gz", 279 | "version": 9 280 | } 281 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # nginxproxymanagerGraf 2 | 3 | some good readme is needed :) 4 | 5 | required things you do beforehand 6 | 7 | 1) create influxdb nginxproxymanagergraf 8 | 2) Create username and password for nginxproxymanagergraf 9 | 3) get your GeoLite2-City.mmdb google is your friend upload it somewhere where you'll find it 10 | 4) Start the docker container 11 | 5) Add data source into grafana 12 | 6) Import the dashboard file and set the new data source 13 | 14 | start docker on the same host where nginx proxy manger runs 15 | 16 | ``` 17 | docker run --name npmgraf -it 18 | -v /home/docker/nginx-proxy-manager/data/logs:/logs \ 19 | -v /home/docker/nginx-proxy-manager/GeoLite2-City.mmdb:/GeoLite2-City.mmdb \ 20 | -e HOME_IPS="192.168.0.*\|192.168.10.*" \ 21 | -e INFLUX_USER=admin -e INFLUX_PW=password \ 22 | -e INFLUX_DB=nginxproxymanagergraf \ 23 | -e INFLUX_HOST=192.168.0.189 \ 24 | -e INFLUX_PORT=8086 \ 25 | makarai/nginx-proxy-manager-graf 26 | ``` 27 | 28 | world map 29 | ``` 30 | SELECT count("IP") AS "counts" FROM "ReverseProxyConnections" WHERE $timeFilter GROUP BY "latitude", "longitude", "IP" 31 | ``` 32 | 33 | 34 | 35 | 36 | Obviously I'd appreciate a grafana Wiz to add some things here :) first time i worked with grafana. 37 | 38 | 39 | 40 | https://github.com/jc21/nginx-proxy-manager 41 | 42 | ![nginx](https://github.com/ma-karai/nginxproxymanagerGraf/blob/master/Screenshot%202021-02-14%20142221.png?raw=true) 43 | -------------------------------------------------------------------------------- /Screenshot 2021-02-14 142221.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ma-karai/nginxproxymanagerGraf/ddb045eeb5da0d8a018a239509518cfe19dfcfb1/Screenshot 2021-02-14 142221.png -------------------------------------------------------------------------------- /sendips.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | # " /bin/sh /Shared/nginx/shtail.sh & " needs to be added to /startapp.sh as the second line 3 | # for ipv6 and ipv4 grep -E -o "(([0-9]{1,3}[\.]){3}[0-9]{1,3}|([0-9a-fA-F]{1,4}:){7,7}[0-9a-fA-F]{1,4}|([0-9a-fA-F]{1,4}:){1,7}:|([0-9a-fA-F]{1,4}:){1,6}:[0-9a-fA-F]{1,4}|([0-9a-fA-F]{1,4}:){1,5}(:[0-9a-fA-F]{1,4}){1,2}|([0-9a-fA-F]{1,4}:){1,4}(:[0-9a-fA-F]{1,4}){1,3}|([0-9a-fA-F]{1,4}:){1,3}(:[0-9a-fA-F]{1,4}){1,4}|([0-9a-fA-F]{1,4}:){1,2}(:[0-9a-fA-F]{1,4}){1,5}|[0-9a-fA-F]{1,4}:((:[0-9a-fA-F]{1,4}){1,6})|:((:[0-9a-fA-F]{1,4}){1,7}|:)|fe80:(:[0-9a-fA-F]{0,4}){0,4}%[0-9a-zA-Z]{1,}|::(ffff(:0{1,4}){0,1}:){0,1}((25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9])\.){3,3}(25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9])|([0-9a-fA-F]{1,4}:){1,4}:((25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9])\.){3,3}(25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9]))" file.txt 4 | # for ipv6 and ipv4 exluding homeips grep -E -o "(([0-9]{1,3}[\.]){3}[0-9]{1,3}|([0-9a-fA-F]{1,4}:){7,7}[0-9a-fA-F]{1,4}|([0-9a-fA-F]{1,4}:){1,7}:|([0-9a-fA-F]{1,4}:){1,6}:[0-9a-fA-F]{1,4}|([0-9a-fA-F]{1,4}:){1,5}(:[0-9a-fA-F]{1,4}){1,2}|([0-9a-fA-F]{1,4}:){1,4}(:[0-9a-fA-F]{1,4}){1,3}|([0-9a-fA-F]{1,4}:){1,3}(:[0-9a-fA-F]{1,4}){1,4}|([0-9a-fA-F]{1,4}:){1,2}(:[0-9a-fA-F]{1,4}){1,5}|[0-9a-fA-F]{1,4}:((:[0-9a-fA-F]{1,4}){1,6})|:((:[0-9a-fA-F]{1,4}){1,7}|:)|fe80:(:[0-9a-fA-F]{0,4}){0,4}%[0-9a-zA-Z]{1,}|::(ffff(:0{1,4}){0,1}:){0,1}((25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9])\.){3,3}(25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9])|([0-9a-fA-F]{1,4}:){1,4}:((25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9])\.){3,3}(25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9]))" | grep -v "192.168.0.*\| 69.0.0.* \| 5.0.0.*" file.txt 5 | # for domains grep -E -o "[a-z0-9]*\.[a-z0-9]*\.(de|net|org|com)" file.txt #working for domains 6 | tail -f /logs/proxy_host* | grep -E "([0-9]{1,3}[\.]){3}[0-9]{1,3}" | while read line; 7 | do 8 | domain=`echo ${line:0:80} | grep -m 1 -o -E "[a-z0-9]*\.[a-z0-9]*\.(de|net|org|com)"` 9 | ipaddressnumber=`echo $line | grep -o -m 1 -E "(([0-9]{1,3}[\.]){3}[0-9]{1,3}|([0-9a-fA-F]{1,4}:){7,7}[0-9a-fA-F]{1,4}|([0-9a-fA-F]{1,4}:){1,7}:|([0-9a-fA-F]{1,4}:){1,6}:[0-9a-fA-F]{1,4}|([0-9a-fA-F]{1,4}:){1,5}(:[0-9a-fA-F]{1,4}){1,2}|([0-9a-fA-F]{1,4}:){1,4}(:[0-9a-fA-F]{1,4}){1,3}|([0-9a-fA-F]{1,4}:){1,3}(:[0-9a-fA-F]{1,4}){1,4}|([0-9a-fA-F]{1,4}:){1,2}(:[0-9a-fA-F]{1,4}){1,5}|[0-9a-fA-F]{1,4}:((:[0-9a-fA-F]{1,4}){1,6})|:((:[0-9a-fA-F]{1,4}){1,7}|:)|fe80:(:[0-9a-fA-F]{0,4}){0,4}%[0-9a-zA-Z]{1,}|::(ffff(:0{1,4}){0,1}:){0,1}((25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9])\.){3,3}(25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9])|([0-9a-fA-F]{1,4}:){1,4}:((25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9])\.){3,3}(25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9]))" | grep -v "$HOME_IPS"` ##UPDATE grep -v with local network 10 | length=`echo $line | awk -F ' ' '{print$14}' | grep -m 1 -o '[[:digit:]]*'` 11 | #device=`echo $line | grep -e ""'('*')'""` 12 | #echo $HOME_IPS 13 | echo $length 14 | echo $ipaddressnumber 15 | echo $domain 16 | #echo $dev 17 | #HomeIP='192.168.0.24' #HomeIP is used to not send your home public ip to keep the number of sends down 18 | #myhomeIP=$(wget -qO- https://icanhazip.com/) 19 | #if [[ "$ipaddressnumber" == "$myhomeIP" ]] 20 | #then 21 | # echo "Home IP" 22 | #else 23 | python /root/.config/NPMGRAF/Getipinfo.py "$ipaddressnumber" "$domain" "$length" 24 | #fi 25 | done 26 | reboot 27 | -------------------------------------------------------------------------------- /start.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | echo "lets go and send connection info to influx" 3 | sh $NPMGRAF_HOME/sendips.sh 4 | 5 | sleep 0.5 6 | tee $NPMGRAF_HOME/nohup.out > /proc/1/fd/1 2>/proc/1/fd/2 7 | --------------------------------------------------------------------------------