Upload files to "/"
This commit is contained in:
@@ -0,0 +1,74 @@
|
||||
# https://app-13.pm.appneta.com/api/v3/dns/webPath/data?from=1557257776&to=1557258076&api_key=v3
|
||||
|
||||
#Python 2.7.6
|
||||
#RestfulClient.py
|
||||
|
||||
import requests
|
||||
from requests.auth import HTTPBasicAuth
|
||||
import json
|
||||
from credentials import username, password, apm_server
|
||||
from influxdb import InfluxDBClient
|
||||
import argparse
|
||||
import time
|
||||
from datetime import datetime, timedelta
|
||||
|
||||
datafrom = 1557257776
|
||||
datato = 1557258076
|
||||
# Replace with the correct URL
|
||||
url = "https://"+apm_server+"/api/v3/dns/webPath/data?from="+str(datafrom)+"&to="+str(datato)+"&api_key=v3"
|
||||
|
||||
# It is a good practice not to hardcode the credentials. So ask the user to enter credentials at runtime
|
||||
#myResponse = requests.get(url,auth=HTTPDigestAuth(username, password), verify=True)
|
||||
myResponse = requests.get(url,auth=HTTPBasicAuth(username, password), verify=True)
|
||||
#print (myResponse.status_code)
|
||||
|
||||
def main(influxhost, influxport):
|
||||
# For successful API call, response code will be 200 (OK)
|
||||
if(myResponse.ok):
|
||||
|
||||
# Loading the response data into a dict variable
|
||||
# json.loads takes in only binary or string variables so using content to fetch binary content
|
||||
# Loads (Load String) takes a Json file and converts into python data structure (dict or list, depending on JSON)
|
||||
jData = json.loads(myResponse.content)
|
||||
|
||||
print("The response contains {0} properties".format(len(jData)))
|
||||
print("\n")
|
||||
print jData
|
||||
# for key in jData:
|
||||
# print (key , " : " , jData[key])
|
||||
else:
|
||||
# If response code is not ok (200), print the resulting http error code with description
|
||||
myResponse.raise_for_status()
|
||||
|
||||
|
||||
# labels, tags, time, count
|
||||
def writeinflux(measurement,tags,time,fields,influxhost,influxport):
|
||||
influxuser = 'CMWrite'
|
||||
influxpass = 'CMWrite'
|
||||
databasename = 'help'
|
||||
client = InfluxDBClient(host=influxhost, port=influxport, username=influxuser, password=influxpass, database=databasename)
|
||||
json_body = [
|
||||
{
|
||||
"measurement": measurement,
|
||||
"tags": tags,
|
||||
"time": time,
|
||||
"fields": fields
|
||||
}
|
||||
]
|
||||
print("Write points: {0}".format(json_body))
|
||||
client.write_points(json_body)
|
||||
|
||||
# Allow command line overrides for host and port influxDB
|
||||
def parse_args():
|
||||
parser = argparse.ArgumentParser(
|
||||
description='Sync Jira items with specific tag into InfluxDB database')
|
||||
parser.add_argument('--host', type=str, required=False, default='itmetricsdb.mathworks.com',
|
||||
help='hostname of InfluxDB http API')
|
||||
parser.add_argument('--port', type=int, required=False, default=8086,
|
||||
help='port of InfluxDB http API')
|
||||
return parser.parse_args()
|
||||
|
||||
# grab arguments
|
||||
if __name__ == '__main__':
|
||||
args = parse_args()
|
||||
main(influxhost=args.host, influxport=args.port)
|
||||
@@ -0,0 +1,35 @@
|
||||
#
|
||||
# Delete paths matching those in "paths.csv"
|
||||
# (Note: No space before or after commas in paths.csv)
|
||||
# (Requests status codes -
|
||||
# https://github.com/requests/requests/blob/master/requests/status_codes.py)
|
||||
#
|
||||
|
||||
import csv
|
||||
from api_fns import *
|
||||
|
||||
with open('paths.csv', mode='r') as csv_file:
|
||||
csv_reader = csv.DictReader(csv_file)
|
||||
for row in csv_reader:
|
||||
# pp_json(row)
|
||||
|
||||
r1 = get_network_path(row['org_id'])
|
||||
if r1.status_code == requests.codes.ok:
|
||||
for network_path in r1.json():
|
||||
if (network_path['sourceAppliance'] == row['source_mp']
|
||||
and network_path['target'] == row['target']):
|
||||
|
||||
r2 = delete_network_path(row['org_id'], row['source_mp'],
|
||||
row['target'])
|
||||
if r2.status_code == requests.codes.no_content:
|
||||
print('Deleted: org/src/targ {}/{}/{} -> id/name {}/{}'
|
||||
.format(row['org_id'],
|
||||
network_path['sourceAppliance'],
|
||||
network_path['target'],
|
||||
network_path['id'],
|
||||
network_path['pathName']))
|
||||
else:
|
||||
print('Unable to delete: {}'
|
||||
.format(r2.json()['messages'][0]))
|
||||
else:
|
||||
print_err(r1)
|
||||
@@ -0,0 +1,26 @@
|
||||
#
|
||||
# Show any paths that match those found in the "paths.csv" file
|
||||
#
|
||||
|
||||
import csv
|
||||
from api_fns import *
|
||||
|
||||
with open('paths.csv', mode='r') as csv_file:
|
||||
csv_reader = csv.DictReader(csv_file)
|
||||
for row in csv_reader:
|
||||
# pp_json(row)
|
||||
|
||||
r1 = get_network_path(row['org_id'])
|
||||
if r1.status_code == requests.codes.ok:
|
||||
for network_path in r1.json():
|
||||
if (network_path['sourceAppliance'] == row['source_mp']
|
||||
and network_path['target'] == row['target']):
|
||||
print('Match: org/src/targ {}/{}/{} -> id/name {}/{}'
|
||||
.format(row['org_id'],
|
||||
network_path['sourceAppliance'],
|
||||
network_path['target'],
|
||||
network_path['id'],
|
||||
network_path['pathName']))
|
||||
# pp_json(network_path)
|
||||
else:
|
||||
print_err(r1)
|
||||
@@ -0,0 +1,25 @@
|
||||
#
|
||||
# Print web path info (grouped by web app group)
|
||||
#
|
||||
from api_fns import *
|
||||
webpathconvert = {}
|
||||
r1 = get_web_app_group()
|
||||
if r1.status_code == requests.codes.ok:
|
||||
for group in r1.json():
|
||||
print('Web app group ({}) name - {} -- org id ({})'.format(group['id'],
|
||||
group['name'], group['orgId']))
|
||||
|
||||
r2 = get_web_path(group['id'])
|
||||
if r2.status_code == requests.codes.ok:
|
||||
for web_path in r2.json():
|
||||
webpathconvert[web_path['id']]=web_path['target']['url']
|
||||
print(' Web path id ({}) MP ({}), target ({}), workflow ({})'
|
||||
.format(web_path['id'],
|
||||
web_path['location']['applianceName'],
|
||||
web_path['target']['url'],
|
||||
web_path['userFlow']['name']))
|
||||
# pp_json(web_path)
|
||||
else:
|
||||
print_err(r2)
|
||||
else:
|
||||
print_err(r1)
|
||||
Reference in New Issue
Block a user