Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

command output contains numerous "Output" headers, but only one is saved #55

Open
bbct opened this issue Oct 29, 2020 · 1 comment
Open

Comments

@bbct
Copy link

bbct commented Oct 29, 2020

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:

  1. 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.
@bbct
Copy link
Author

bbct commented Oct 30, 2020

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)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant