forked from evijayan2/nginxproxymanagerGraf
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathGetipinfo.py
75 lines (61 loc) · 1.92 KB
/
Getipinfo.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
#!/usr/bin/python3
import sys
import geoip2.database
import socket
import datetime
import influxdb_client
from influxdb_client.client.write_api import SYNCHRONOUS
import os
print ('*************************************')
print (sys.argv[1])
print(socket.gethostname())
reader = geoip2.database.Reader('/GeoLite2-City.mmdb')
response = reader.city(str(sys.argv[1]).strip())
Lat = response.location.latitude
ISO = response.country.iso_code
Long = response.location.longitude
State = response.subdivisions.most_specific.name
City = response.city.name
Country = response.country.name
Zip = response.postal.code
IP = str(sys.argv[1]).strip()
Domain = str(sys.argv[2]).strip()
duration = int(sys.argv[3])
reader.close()
# Get environment variables
ifhost = os.getenv('INFLUX_HOST')
ifport = os.getenv('INFLUX_PORT')
ifbucket = os.getenv('INFLUX_BUCKET')
iforg = os.getenv('INFLUX_ORG')
iftoken = os.getenv('INFLUX_TOKEN')
print(ifbucket, iforg, ifhost, ifport)
hostname = socket.gethostname()
measurement_name = ("ReverseProxyConnections")
print ('*************************************')
time = datetime.datetime.utcnow()
ifclient = influxdb_client.InfluxDBClient(
url=f"http://{ifhost}:{ifport}",
org=iforg,
token=iftoken
)
write_api = ifclient.write_api(write_options=SYNCHRONOUS)
point = influxdb_client.Point(measurement_name)
point.tag("key", ISO)
point.tag("Latitude", Lat)
point.tag("Longitude", Long)
point.tag("Domain", Domain)
point.tag("City", City)
point.tag("State", State)
point.tag("Name", Country)
point.tag("IP", IP)
point.field("Domain", Domain)
point.field("Latitude", Lat)
point.field("Longitude", Long)
point.field("State", State)
point.field("City", City)
point.field("key", ISO)
point.field("IP", IP)
point.field("Name", Country)
point.field("duration", duration)
point.field("metric", 1)
write_api.write(bucket=ifbucket, org=iforg, record=point)