Skip to content

Commit

Permalink
Merge pull request #18 from smilebasti/v2.3.0-release
Browse files Browse the repository at this point in the history
V2.3.0 release
  • Loading branch information
smilebasti authored Jun 15, 2023
2 parents d65fb83 + d882970 commit 8466f85
Show file tree
Hide file tree
Showing 11 changed files with 2,611 additions and 1,143 deletions.
3 changes: 3 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,9 @@ RUN pip install -r /root/.config/NPMGRAF/requirements.txt
COPY Getipinfo.py /root/.config/NPMGRAF/Getipinfo.py
RUN chmod +x /root/.config/NPMGRAF/Getipinfo.py

COPY Internalipinfo.py /root/.config/NPMGRAF/Internalipinfo.py
RUN chmod +x /root/.config/NPMGRAF/Internalipinfo.py

COPY sendips.sh /root/.config/NPMGRAF/sendips.sh
RUN chmod +x /root/.config/NPMGRAF/sendips.sh

Expand Down
17 changes: 6 additions & 11 deletions Getipinfo.py
Original file line number Diff line number Diff line change
@@ -1,17 +1,14 @@
#!/usr/bin/python3

import sys
# import geoip2.webservice
print ('**************** start *********************')
measurement_name = (sys.argv[5]) #f get measurement from argv
measurement_name = (sys.argv[5]) # get measurement from argv
print ('Measurement-name: '+measurement_name)

# argv1 = outsideip, agrv2 = Domain, argv3 length, argv4 tragetip
# print ('Outside-ip: ', sys.argv[1])

import geoip2.database
import socket


# IP gets infos from the DB
reader = geoip2.database.Reader('/geolite/GeoLite2-City.mmdb')
Expand Down Expand Up @@ -42,8 +39,6 @@
print ('Domain: ', Domain)
reader.close()


import datetime
import influxdb_client
from influxdb_client.client.write_api import SYNCHRONOUS

Expand Down Expand Up @@ -87,7 +82,7 @@
month = '12'

# build new time
time=oldtime[7:11]+'-'+month+'-'+oldtime[0:2]+'T'+oldtime[12:20]+'.000000Z'
time=oldtime[7:11]+'-'+month+'-'+oldtime[0:2]+'T'+oldtime[12:20]+oldtime[21:24]+':'+oldtime[24:26]
print('Measurement Time: ', time)

ifclient = influxdb_client.InfluxDBClient(
Expand All @@ -101,8 +96,8 @@

point = influxdb_client.Point(measurement_name)
point.tag("key", ISO)
point.tag("Latitude", Lat)
point.tag("Longitude", Long)
point.tag("latitude", Lat)
point.tag("longitude", Long)
point.tag("Domain", Domain)
point.tag("City", City)
point.tag("State", State)
Expand All @@ -111,8 +106,8 @@
point.tag("Target", Target)

point.field("Domain", Domain)
point.field("Latitude", Lat)
point.field("Longitude", Long)
point.field("latitude", Lat)
point.field("longitude", Long)
point.field("State", State)
point.field("City", City)
point.field("key", ISO)
Expand Down
92 changes: 92 additions & 0 deletions Internalipinfo.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,92 @@
#!/usr/bin/python3

import sys
print ('**************** start *********************')
measurement_name = (sys.argv[5]) # get measurement from argv
print ('Measurement-name: '+measurement_name)

# argv1 = outsideip, agrv2 = Domain, argv3 length, argv4 tragetip

import socket

IP = str(sys.argv[1])
Domain = str(sys.argv[2])
duration = int(sys.argv[3])
Target = str(sys.argv[4])

# print to log
print ('Calling IP: ', IP)
print ('Target IP: ', Target)
print ('Domain: ', Domain)

import influxdb_client
from influxdb_client.client.write_api import SYNCHRONOUS

## get env vars and use
import os
# influx configuration - edit these

npmhome = "/root/.config/NPMGRAF"
ifhost = os.getenv('INFLUX_HOST')
ifbucket = os.getenv('INFLUX_BUCKET')
iforg = os.getenv('INFLUX_ORG')
iftoken = os.getenv('INFLUX_TOKEN')

# take a timestamp for this measurement
oldtime = str(sys.argv[6]) #30/May/2023:14:16:48 +0000 to 2009-11-10T23:00:00+00:00 (+00:00 is Timezone)
#transform month
month = oldtime[3:6]
if month == 'Jan':
month = '01'
elif month =='Feb':
month = '02'
elif month =='Mar':
month = '03'
elif month =='Apr':
month = '04'
elif month =='May':
month = '05'
elif month =='Jun':
month = '06'
elif month =='Jul':
month = '07'
elif month =='Aug':
month = '08'
elif month =='Sep':
month = '09'
elif month =='Oct':
month = '10'
elif month =='Nov':
month = '11'
else:
month = '12'

# build new time
time=oldtime[7:11]+'-'+month+'-'+oldtime[0:2]+'T'+oldtime[12:20]+oldtime[21:24]+':'+oldtime[24:26]
print('Measurement Time: ', time)

ifclient = influxdb_client.InfluxDBClient(
url=ifhost,
token=iftoken,
org=iforg
)

# write the measurement
write_api = ifclient.write_api(write_options=SYNCHRONOUS)

point = influxdb_client.Point(measurement_name)
point.tag("Domain", Domain)
point.tag("IP", IP),
point.tag("Target", Target)

point.field("Domain", Domain)
point.field("IP", IP)
point.field("Target", Target)
point.field("duration", duration)
point.field("metric", 1)

point.time(time)

write_api.write(bucket=ifbucket, org=iforg, record=point)

print ('*************** data send ******************')
Loading

0 comments on commit 8466f85

Please sign in to comment.