[Freeswitch-users] Trying to get short hostname
Antony Stone
Antony.Stone at freeswitch.open.source.it
Thu Oct 28 12:50:38 UTC 2021
Hi.
I'm using FreeSwitch 1.10.7 as a client registering to other PBXs as well as a
SIP server itself.
I am setting the user-agent string in the SIP profile, such as:
<param name="user-agent-string" value="FS $${CFGver} $${hostname}"/>
The variable $${CFGver}} is a version string I'm definiing in vars.xml
This is working, but it gives me the FQDN of the machine as $${hostname}} and
I really only want the machine name without the domain.
I've found
https://freeswitch.org/confluence/display/FREESWITCH/Regular+Expression and
https://freeswitch.org/confluence/display/FREESWITCH/mod_dptools:+regex and
I've tried to use them to cut the domain off the value of $${hostname} but with
no success:
In vars.xml:
<X-PRE-PROCESS cmd="set" data="shorthostname=${regex($${hostname}|([^\.]*).*|
%1)}"/>
This results in the variable shorthostname being assigned the value:
%{regex(abcd.efgh.tld|([^\.]*).*|%1)}
where abcd.efgh.tld is the server's FQDN.
Instead of doing that in vars.xml and creating the variable shorthostname, I
tried putting the regex into the SIP profile:
<param name="user-agent-string" value="FS $${CFGver} ${regex($${hostname}|
([^\.]*).*|%1)}"/>
This ends up with precisely the same result. The ${regex(....)} function
simply isn't being executed.
Given that the machine's hostname is also available from the system command
"hostname -s" I decided to try that instead:
In vars.xml:
<X-PRE-PROCESS cmd="set" data="shorthostname=${system(hostname -s)}"/>
Or in the SIP profile definition:
<param name="user-agent-string" value="FS $${CFGver} ${system(hostname -s)}"/>
These both produce the output:
FS 0.65 ${system(hostname -s)}
In other words, the ${system(....)} command isn't working any more than
${regex(....)} did.
What am I doing wrong please?
How can I get the machine's short hostname into a user-agent string for
registration to a server?
Thanks,
Antony.
--
Perfection in design is achieved not when there is nothing left to add, but
rather when there is nothing left to take away.
- Antoine de Saint-Exupery
Please reply to the list;
please *don't* CC me.
More information about the FreeSWITCH-users
mailing list