The below python script executes a command. The command returns an output. Output is listed below.
I need to parse the following from the output.
1) HTTP response code 2) Contents of points array. Array could be empty, or non empty array (last line of the output)
OUTPUT :
Matched line for host akaa-wcb54zu2flskjhx4-szsapxzmalbot2fr.luna-dev.akamaiapis.net
{'access_token': 'akaa-r6gnip3mmql3evrj-mgiex4eajadrjltu', 'max-body': 131072, 'secret': 'yBc1LSGKBd6+sSP5tTR2o+YxlNYvlYNjWGdCFDl6Xt0=', 'signed-header': [], 'host': 'akaa-wcb54zu2flskjhx4-szsapxzmalbot2fr.luna-dev.akamaiapis.net', 'client_token': 'akaa-eyaa6fvcfngdlrb6-uxvn3hkpzxx33oxc'}
[]
Canonicalized header:
Auth data: EG1-HMAC-SHA256 client_token=akaa-eyaa6fvcfngdlrb6-uxvn3hkpzxx33oxc;access_token=akaa-r6gnip3mmql3evrj-mgiex4eajadrjltu;timestamp=20180410T16:38:24+0000;nonce=265e61d8-813c-4c3a-9edb-91caaa027420;
String-to-sign: POST https akaa-wcb54zu2flskjhx4-szsapxzmalbot2fr.luna-dev.akamaiapis.net /prolexic-analytics/v2/metrics YSycIdG2e9nY8KVLrPvMfzrBNMZEI8ncRxtcUP4h1J0= EG1-HMAC-SHA256 client_token=akaa-eyaa6fvcfngdlrb6-uxvn3hkpzxx33oxc;access_token=akaa-r6gnip3mmql3evrj-mgiex4eajadrjltu;timestamp=20180410T16:38:24+0000;nonce=265e61d8-813c-4c3a-9edb-91caaa027420;
args = ['curl', '-H', 'Authorization: EG1-HMAC-SHA256 client_token=akaa-eyaa6fvcfngdlrb6-uxvn3hkpzxx33oxc;access_token=akaa-r6gnip3mmql3evrj-mgiex4eajadrjltu;timestamp=20180410T16:38:24+0000;nonce=265e61d8-813c-4c3a-9edb-91caaa027420;signature=p6y+oDzaTfh3nj32R8jveDx8EGmjpHGybL7LJ0L+Adk=', '-S', '-i', '-k', '-X', 'POST', '-H', 'Host:akaa-wcb54zu2flskjhx4-szsapxzmalbot2fr.luna-dev.akamaiapis.net', '-H', 'Content-Type: application/json', '-H', 'Accept: application/json', '-d', '{"contract": "amade", "start": 1522420500, "end": 1522424147, "samples": 20, "type": {"connect": ["bandwidthIn"]}}', 'https://akaa-wcb54zu2flskjhx4-szsapxzmalbot2fr.luna-dev.akamaiapis.net/prolexic-analytics/v2/metrics', '-H', 'Expect:']
HTTP/1.1 200 OK
Server: Apache-Coyote/1.1
Content-Type: application/json
Content-Length: 151
X-Trace-Id: c4db5acce87c20f3
Date: Tue, 10 Apr 2018 16:38:26 GMT
Connection: keep-alive
{"status":true,"currentContract":"amade","statusMsg":"Metrics acquired successfully","data":[{"service":"connect","metric":"bandwidthIn","points":[]}]}
SCRIPT :
import subprocess
import sys
import re
n = sys.argv[1]
for i in range(int(n)):
# command to be executed
cmd = "python egcurl --eg-config .egcurl -Sik -X POST --eg-verbose -H 'Host:akaa-wcb54zu2flskjhx4-szsapxzmalbot2fr.luna-dev.akamaiapis.net' -H 'Content-Type: application/json' -H 'Accept: application/json' -d '{'contract': 'amade', 'start': 1522420500, 'end': 1522424147, 'samples': 20, 'type': {'connect': ['bandwidthIn']}}' https://akaa-wcb54zu2flskjhx4-szsapxzmalbot2fr.luna-dev.akamaiapis.net/prolexic-analytics/v2/metrics"
cmd_exec = subprocess.call(cmd, shell=True)
r1 = re.search("HTTP(.*)",cmd_exec)
print(r1)
print(cmd_exec)
error:
File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/re.py", line 146, in search
return _compile(pattern, flags).search(string)
TypeError: expected string or buffer