You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Because there are several "Output" headers in the output of the "core show channels concise" command, it appears the response is only keeping the very last one.
I execute the following code after initiating a manager instance successfully:
response = manager.command("core show channels concise")
print(response.get_header("Output"))
The output to the print is as follows:
SIP/callcentric19-00000077!macro-dial-one!s!56!Up!Dial!SIP/10,15,HhtrIb(func-apply-sipheaders^s^1)!100!!!3!146!83324977-96e4-4ea9-98f9-19f23b472c7e!1604003497.139
Running AMI in Telnet shows the following, -> is sent lines, <- is received lines:
->action: command
->command: core show channels concise
->
<-Response: Success
<-Message: Command output follows
<-Output: SIP/10-00000078!from-internal!!1!Up!AppDial!(Outgoing Line)!10!!!3!27!83324977-96e4-4ea9-98f9-19f23b472c7e!1604003508.140
<-Output: SIP/callcentric19-00000077!macro-dial-one!s!56!Up!Dial!SIP/10,15,HhtrIb(func-apply-sipheaders^s^1)!100!!!3!38!83324977-96e4-4ea9-98f9-19f23b472c7e!1604003497.139
Notice there are two Output header lines...
Proposed solution:
if there are multiple headers with the same name, perhaps they could be stored in an array. A new get_header_array() method could return the results in an array. If only one came back, get_header_array() would return an array of 1, but if multiple came back, return the array of all of them. One would use this method when expecting possibly more than one (is this the only case where that happens, when running a command? I am not sure).
get_header() would likely still return the last one for backward compatibility.
The text was updated successfully, but these errors were encountered:
I may create a pull request to make the Output header always return a list of all the Output values. Meanwhile I have this workaround...
I borrowed the parse logic from the ManagerMsg class parse() method to create a Function called parseOutput shown below, which will only look for Output messages, and put their values into a list. It returns that list.
After I run my command, which I know can return multiple Output: response lines, I take the raw response from the result and pass it to this function, which will parse it the way I wish, and return a list of the Output string values.
Come to think of it, could just create a new method of ManagerMsg called, perhaps, getOutputs(), and leave the original parse() method alone.
def parseOutput(response):
out = []
for n, line in enumerate(response):
# all valid header lines end in \r\n
if not line.endswith('\r\n'):
break
try:
k, v = (x.strip() for x in line.split(':', 1))
if 'Output' in k:
out.append(v)
except ValueError:
break
return out
# Example using this new function, get the results of the "core show channels concise' command and parse it
respMsg = manager.command("core show channels concise")
out = parseOutput(respMsg.response)
for call in out:
print("call: ", call)
Because there are several "Output" headers in the output of the "core show channels concise" command, it appears the response is only keeping the very last one.
I execute the following code after initiating a manager instance successfully:
response = manager.command("core show channels concise")
print(response.get_header("Output"))
The output to the print is as follows:
SIP/callcentric19-00000077!macro-dial-one!s!56!Up!Dial!SIP/10,15,HhtrIb(func-apply-sipheaders^s^1)!100!!!3!146!83324977-96e4-4ea9-98f9-19f23b472c7e!1604003497.139
Running AMI in Telnet shows the following, -> is sent lines, <- is received lines:
->action: command
->command: core show channels concise
->
<-Response: Success
<-Message: Command output follows
<-Output: SIP/10-00000078!from-internal!!1!Up!AppDial!(Outgoing Line)!10!!!3!27!83324977-96e4-4ea9-98f9-19f23b472c7e!1604003508.140
<-Output: SIP/callcentric19-00000077!macro-dial-one!s!56!Up!Dial!SIP/10,15,HhtrIb(func-apply-sipheaders^s^1)!100!!!3!38!83324977-96e4-4ea9-98f9-19f23b472c7e!1604003497.139
Notice there are two Output header lines...
Proposed solution:
get_header() would likely still return the last one for backward compatibility.
The text was updated successfully, but these errors were encountered: