Closed alexpts closed 5 years ago
Hi Alex,
CommandAction is just going to execute a CLI command, you give it and return the CLI output (string) to you as far as i know. The is no real way to format the returned string into anything sensible.
However CommandAction is handled a little differently then other messages, because it returns a CommandResponse. So if we should do some extra processing, we can do that here. You can use getCommandOutput()
to retrieve the output in question, no need to go through the rawContent.
If you mean output is currently not being filled/processed correctly and getCommandOutput does not work then i mis understood, and we should correct/fix that. Let me know if i misunderstood and i can look into it later today.
I think i know what might be going wrong here, we are only setting $output to the last line of the returned output. For example running:
$ca = new CommandAction('sip show peers');
$cr = $a->send($ca);
var_dump($cr);
echo($cr->getCommandOutput());
Would return:
2 sip peers [Monitored: 1 online, 1 offline Unmonitored: 0 online, 0 offline]
Instead of:
Name/username Host Dyn Forcerport Comedia ACL Port Status Description
1234/1234 (Unspecified) D Yes Yes A 0 UNKNOWN
1235/1235 192.168.178.100 D Yes Yes A 5060 "...
2 sip peers [Monitored: 1 online, 1 offline Unmonitored: 0 online, 0 offline]
That will have to be fixed.
Method getCommandOutput
returns empty string
Message->setSanitizedKey
rewrite all Output
key for all line
Each line from raw content parse via Message->setSanitizedKey.
Key output
may many times in response. Response has only last output message instead array with all output message for this case
object(PAMI\Message\Response\CommandResponse)[326]
protected 'events' =>
array (size=0)
empty
protected 'completed' => boolean true
protected 'rawContent' => string 'Response: Success
ActionID: 1573115294.4539
Message: Command output follows
Output: conversionq has 0 calls (max unlimited) in 'ringall' strategy (0s holdtime, 0s talktime), W:5, C:0, A:0, SL:0.0%, SL2:0.0% within 20s
Output: No Members
Output: No Callers
Output:
Output: callsq has 0 calls (max unlimited) in 'ringall' strategy (0s holdtime, 0s talktime), W:0, C:0, A:0, SL:0.0%, SL2:0.0% within 0s
Output: No Members
Output: No Callers
Output:
Output: marketplaceq has 0 calls (max unl'... (length=1943)
protected 'channelVariables' =>
array (size=1)
'default' =>
array (size=0)
empty
protected 'statusVariables' =>
array (size=1)
'default' =>
array (size=0)
empty
protected 'lines' =>
array (size=0)
empty
protected 'variables' =>
array (size=0)
empty
protected 'keys' =>
array (size=4)
'response' => string 'Success' (length=7)
'actionid' => string '1573115294.4539' (length=15)
'message' => string 'Command output follows' (length=22)
'output' => null
protected 'createdDate' => int 1573115294
public 'eventsCount' => int 0
I think key output
must be array of strings
You are right, we should be able to include that in CommandResponse.php. Have not had time though.
I have a simple solution, using your pointers, which seems to work, testing now.
Update Message/Response/CommandResponse.php:
Git Checkout this temporary branch
git pull
git fetch -a
git branch
git checkout issues/6
move back to master branch afterward testing:
git checkout master
If it works and is useable, we can update the docs and merge it back into the master branch. Please give it a go. Thanks for helping out guiding me in the right direction, has been a while since i worked on the code :-) if you have some ideas to do it in a nicer way, let me know
Thanks! I will be wait new release for composer :)
Ooh it would not generate one automatically, because i put it in a seperate branch... I will merge it right now (should be fine :-))
BTW: You can use composer to point at the master branch using: composer.json
....
"repositories": [
{
"url": "https://github.com/chan-sccp/PAMI.git",
"type": "git"
}
],
"require-dev": {
"chan-sccp/pami": "dev-master",
}
Pushed and merged the issues/6 branch into master ! Please test/check and re-open if necessary Thanks for the issue report and helping in fixing it.
@alexpts We are trimming the result and 'loosing' the indentation in your 'queue show' example. I am not sure how important that is you. If need be you can still get that from the rawContent of course.
@alexpts I have updated composer/packagist package so you can update to v2.0.4 when you want to.
RawContent:
Response keys:
I expected array with messages in
output
field.