1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

How do you detect the version of asterisk that is running?

Discussion in 'Help' started by tshif, Aug 7, 2010.

  1. tshif

    tshif
    Expand Collapse
    Guru

    Joined:
    Jan 3, 2008
    Messages:
    1,240
    Likes Received:
    2
    With the dial plan syntax changes that we have to deal with on a regular basis (between Asterisk 1.4 and 1.6 for example) - it would be very helpful if we could detect what version of Atserisk was running from within the dial plan.

    Ive been hunting around for a while, and havent found a way to do this - does anyone have any idea, or refrence link that might help out?
     
  2. jroper

    jroper
    Expand Collapse
    Guru

    Joined:
    Oct 20, 2007
    Messages:
    3,825
    Likes Received:
    63
    Hi

    Just for interest, try using a , instead of |on the "Gold" release of PiaF. I know that later versions of 1.4 support the use of either.

    Joe
     
  3. tshif

    tshif
    Expand Collapse
    Guru

    Joined:
    Jan 3, 2008
    Messages:
    1,240
    Likes Received:
    2
    Thats good to know - Im glad they are making syntaxes obsolete - it really messes with a lot of existing code when they do that.

    But for earlier version....

    Please check out the Bug ticket here. I have done some research, and there is a possible workaround - but Id like your opinion also.
     
  4. MyKroFt

    MyKroFt
    Expand Collapse
    Guru

    Joined:
    Oct 31, 2008
    Messages:
    655
    Likes Received:
    3
    How about this?

    Code:
    [noah-swift]
    exten => s,1,Answer
    exten => s,n,Wait(1)
    exten => s,n,Set(TIMEOUT(digit)=7)
    exten => s,n,Set(TIMEOUT(response)=10)
    exten => s,n,swift("At the beep enter the five digit zip code for the weather report you wish to retrieve.")
    exten => s,n,Read(ZIPCODE,beep,5)
    exten => s,n,swift("Please hold a moment while we contact the National Weather Service for your report.")
    exten => s,n,ReadFile(VERSION=/etc/asterisk/version,12)
    exten => s,n,GotoIf($["${VERSION}" = "Asterisk 1.6"]?agi16)
    exten => s,n,AGI(nvweather-zip.php|${ZIPCODE})
    exten => s,n(agi16),AGI(nvweather-zip.php,${ZIPCODE})
    exten => s,n,NoOp(Wave file: ${TMPWAVE})
    exten => s,n,Playback(${TMPWAVE})
    exten => s,n,Hangup
    
    [noah-flite]
    exten => s,1,Answer
    exten => s,n,Wait(1)
    exten => s,n,Set(TIMEOUT(digit)=7)
    exten => s,n,Set(TIMEOUT(response)=10)
    exten => s,n,Flite("At the beep enter the five digit zip code for the weather report you wish to retrieve.")
    exten => s,n,Read(ZIPCODE,beep,5)
    exten => s,n,Flite("Please hold a moment while we contact the National Weather Service for your report.")
    exten => s,n,ReadFile(VERSION=/etc/asterisk/version,12)
    exten => s,n,GotoIf($["${VERSION}" = "Asterisk 1.6"]?agi16)
    exten => s,n,AGI(nvweather-zip.php|${ZIPCODE})
    exten => s,n(agi16),AGI(nvweather-zip.php,${ZIPCODE})
    exten => s,n,NoOp(Wave file: ${TMPWAVE})
    exten => s,n,Playback(${TMPWAVE})
    exten => s,n,Hangup
    
    Myk
     
  5. MyKroFt

    MyKroFt
    Expand Collapse
    Guru

    Joined:
    Oct 31, 2008
    Messages:
    655
    Likes Received:
    3
    could make the readfile part into a include conf file setting a specific PIAFASTERISKVER variable, then any of the piaf scripts and use that variable?
     
  6. tshif

    tshif
    Expand Collapse
    Guru

    Joined:
    Jan 3, 2008
    Messages:
    1,240
    Likes Received:
    2
    Both suggestions are good. Would you please post them into the bug ticket here. Your a registered developer on the project - and thats where the bulk of the notes are.
     
  7. Lost Trunk

    Lost Trunk
    Expand Collapse
    Guru

    Joined:
    Aug 5, 2008
    Messages:
    228
    Likes Received:
    0
    I'm not an expert on this but couldn't you also do something like

    System(/usr/sbin/asterisk -rx "show version" > /tmp/version.txt)

    ...possibly with some additional piping and filtering to extract only the version number - I'm not much of a command line user so I'm not sure which command might be appropriate.

    Then you could read the version.txt file to get what you need.
     
  8. jroper

    jroper
    Expand Collapse
    Guru

    Joined:
    Oct 20, 2007
    Messages:
    3,825
    Likes Received:
    63
    You could, but of course the command for asterisk 1.6.2 is "core show version", which means that you have to determine the asterisk version before knowing what command to query the version ??? ;-)

    Now could be the time for the cliche'd "bangs head against wall" smiley but they make my teeth itch.

    Joe
     
  9. MyKroFt

    MyKroFt
    Expand Collapse
    Guru

    Joined:
    Oct 31, 2008
    Messages:
    655
    Likes Received:
    3
    Im sure FreePbx has a variable loaded somewhere with the asterisk version already, but I cant find it. Cause I assume its what has written /etc/asterisk/version in the 1st place.....?
     
  10. MyKroFt

    MyKroFt
    Expand Collapse
    Guru

    Joined:
    Oct 31, 2008
    Messages:
    655
    Likes Received:
    3
    the ip-country and weather by airport code are prob broken for 1.6 also because of this - perty much anything that makes a AGI call to a external script is effected
     
  11. MyKroFt

    MyKroFt
    Expand Collapse
    Guru

    Joined:
    Oct 31, 2008
    Messages:
    655
    Likes Received:
    3
    this is true, but current version of 1.4.21.4 will use the core show version as well, along with the comma instead of the pipe fpr AGI calls, but 1.2 as far as I know uses only the old way.

    but again, at what version in 1.4 did they change, so we still have to compensate for older 1.4.x trees.....
     
  12. tshif

    tshif
    Expand Collapse
    Guru

    Joined:
    Jan 3, 2008
    Messages:
    1,240
    Likes Received:
    2
    Maybe, but I dont have modules for these.
     
  13. tshif

    tshif
    Expand Collapse
    Guru

    Joined:
    Jan 3, 2008
    Messages:
    1,240
    Likes Received:
    2

    Im really liking this approach.
     
  14. MyKroFt

    MyKroFt
    Expand Collapse
    Guru

    Joined:
    Oct 31, 2008
    Messages:
    655
    Likes Received:
    3
    the
    exten => s,n,ReadFile(VERSION=/etc/asterisk/version,12)

    is the only surefire way I can figure out asterisk version so far.

    I am sure freepbx has a populated variable somewhere already in the dialplan, but i cant find it yet. Am also assuming freepbx is making that version file as well. Its in all the boxes I have check on so far.

    should prob modify the gotoif to check grab just the x.x part of the version and do a evail if it is 1.6 or greater for future reference...
     
  15. wardmundy

    wardmundy
    Expand Collapse
    Nerd Uno

    Joined:
    Oct 12, 2007
    Messages:
    12,150
    Likes Received:
    1,703
    asterisk -rx "core show version"
     
  16. MyKroFt

    MyKroFt
    Expand Collapse
    Guru

    Joined:
    Oct 31, 2008
    Messages:
    655
    Likes Received:
    3
    yes, that is avail on which ever ver of 1.4.x when they implemented it, older versions of 1.4 don't support the core command

    Code:
    Asterisk 1.4.21.2 built by root @ pbx.local on a i686 running Linux on 2010-07-29 19:30:28 UTC
    root@pbxcb:~ $ asterisk -rx "show version"     
    Asterisk 1.4.21.2 built by root @ pbx.local on a i686 running Linux on 2010-07-29 19:30:28 UTC
    The 'show version' command is deprecated and will be removed in a future release. Please use 'core show version' instead.
    by using core command, still need to find out what specific 1.4.x to be able to use it on
     
  17. tshif

    tshif
    Expand Collapse
    Guru

    Joined:
    Jan 3, 2008
    Messages:
    1,240
    Likes Received:
    2
    Yes - this seems to be the most reliable method - I dont think we have to worry about exaxctly which release supports both, as long as we support the native syntax for each ver.release.
     
  18. MyKroFt

    MyKroFt
    Expand Collapse
    Guru

    Joined:
    Oct 31, 2008
    Messages:
    655
    Likes Received:
    3
    found it - defined in extensions_additional.conf in the [global] section

    Code:
    ASTVERSION = 1.6.2.9
    so we can just test against that variable
     
  19. wardmundy

    wardmundy
    Expand Collapse
    Nerd Uno

    Joined:
    Oct 12, 2007
    Messages:
    12,150
    Likes Received:
    1,703
    This is another good example of what happens when you're always screwing around with syntax... makes it virtually impossible to write stable code. :eek:
     

Share This Page