forked from smilebasti/npmGrafStats
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathInternalipinfo.py
94 lines (76 loc) · 2.12 KB
/
Internalipinfo.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
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
#!/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)
ifclient.close()
print ('*************** data send ******************')