Can't connect to ARI, receive 404


#1

I’m new to Asterisk.

I’ve a fresh install of Asterisk 14. I’ve registered 2 phones (my pc and my cellphone) successfully. I’m following this example in order to make an IVR using node.js but I got stuck at connecting using wscat.

https://wiki.asterisk.org/wiki/display/AST/Getting+Started+with+ARI

As I try to connect using wscat I receive “error: Error: unexpected server response (404)”.

Is there a module I’m missing or need to activate? How do I activate a module?

Also if I run

*CLI> ari show status

I get “no such command”.

Any suggestions? Thank you very much.

I’ve found this command that shows that ws/ is enabled…but I still get 404

update: If I try to connect using node.js client (https://github.com/asterisk/node-ari-client) I get this error so I guess ARI is not enabled in my asterisk. How do I enable it?


#2

I was running asterisk 11. Don’t know really why because I downloaded last version of AsteriskNow. Got really confused with the UI which allowed me to configure ARI but this version of Asterisk doesn’t suppor ARI. Installing version 13 now.

You may close this post.


#3

Things don’t really “close”. They just stop getting responded to.

(Welcome to posterity :smile:)


#4

you do not enable ARI module yet. Try to enable this module by command ‘module load app_ari.so’


#5

Hi,

I have also facing similary issue - that I am unable to get reponse from ari. I am following this guide - https://wiki.asterisk.org/wiki/display/AST/Getting+Started+with+ARI

But getting 404 response from ari when I try to do wscat

root@Sandeep-PC:~# wscat -c "ws://localhost:8088/ari/events?api_key=asterisk:asterisk&app=hello-world"

I am adding some premilinary information before hand - which might help in identifying the issue:

Sandeep-PC*CLI> core show version
#Asterisk 16.0.0 built by root @ Sandeep-PC on a x86_64 running Linux on 2018-10-19 14:29:19 UTC
Sandeep-PC*CLI> ari show status
ARI Status:
Enabled: Yes
Output format: pretty
Auth realm: Asterisk REST Interface
Allowed Origins: http://ari.asterisk.org
User count: 1

When I connect, I can see the below output in asterisk console:

Sandeep-PC*CLI> <--- ARI request received from: 127.0.0.1:40476 --->
Sec-WebSocket-Version: 13
Sec-WebSocket-Key: f3Rbo3CccfhVB7EO5b8K9g==
Connection: Upgrade
Upgrade: websocket
Sec-WebSocket-Extensions: permessage-deflate; client_max_window_bits
Host: localhost:8088
api_key: asterisk:asterisk
app: hello-world
body:


<--- Sending ARI response to 127.0.0.1:40476 --->
<--- ARI request received from: 127.0.0.1:40476 --->
Sec-WebSocket-Version: 13
404 Not Found
Content-type: application/json
Sec-WebSocket-Key: f3Rbo3CccfhVB7EO5b8K9g==
Connection: Upgrade
{
Upgrade: websocket
Sec-WebSocket-Extensions: permessage-deflate; client_max_window_bits
Host: localhost:8088
api_key: asterisk:asterisk
  "message": "Resource not found"
app: hello-world
body:

}


<--- Sending ARI response to 127.0.0.1:40476 --->
404 Not Found
Content-type: application/json
{
  "message": "Resource not found"
}

Below is ari.conf

[general]
enabled = yes       ; When set to no, ARI support is disabled.
pretty = yes        ; When set to yes, responses from ARI are
;                   ; formatted to be human readable.
;allowed_origins =  ; Comma separated list of allowed origins, for
;                   ; Cross-Origin Resource Sharing. May be set to * to
;                   ; allow all origins.
;auth_realm =       ; Realm to use for authentication. Defaults to Asterisk
;                   ; REST Interface.
;
; Default write timeout to set on websockets. This value may need to be adjusted
; for connections where Asterisk must write a substantial amount of data and the
; receiving clients are slow to process the received information. Value is in
; milliseconds; default is 100 ms.
;websocket_write_timeout = 100
;
; Display certain channel variables every time a channel-oriented
; event is emitted:
;
;channelvars = var1,var2,var3

allowed_origins=http://ari.asterisk.org

[asterisk]
type = user        ; Specifies user configuration
read_only = no     ; When set to yes, user is only authorized for
;                   ; read-only requests.
;
password = asterisk        ; Crypted or plaintext password (see password_format).
;
; password_format may be set to plain (the default) or crypt. When set to crypt,
; crypt(3) is used to validate the password. A crypted password can be generated
; using mkpasswd -m sha-512.
;
; When set to plain, the password is in plaintext.
;
password_format = plain


#6

I checked from swagger http://ari.asterisk.org/ that the GET and POST methods are working

but the StasisStart event can not be started in any way. I have tried running code samples given by @vallo earlier, For example, I get below output if I run the channel-dump code by running command: node example.js:

root@Sandeep-PC:/var/www/html/ari/channel-dump# node example.js
[ 'This API is using a deprecated version of Swagger!  Please see http://github.com/wordnik/swagger-core/wiki for more info' ]
No channels currently :-(
Unhandled rejection Error: Connection attempts exceeded WebSocketMaxRetries. unexpected server response (404)
    at reconnect (/var/www/html/ari/node_modules/ari-client/lib/client.js:539:16)
    at WebSocket.processError (/var/www/html/ari/node_modules/ari-client/lib/client.js:522:7)
    at emitOne (events.js:116:13)
    at WebSocket.emit (events.js:211:7)
    at ClientRequest.response (/var/www/html/ari/node_modules/ws/lib/WebSocket.js:721:12)
    at Object.onceWrapper (events.js:315:30)
    at emitOne (events.js:116:13)
    at ClientRequest.emit (events.js:211:7)
    at HTTPParser.parserOnIncomingClient [as onIncoming] (_http_client.js:544:21)
    at HTTPParser.parserOnHeadersComplete (_http_common.js:117:17)
    at Socket.socketOnData (_http_client.js:440:20)
    at emitOne (events.js:116:13)
    at Socket.emit (events.js:211:7)
    at addChunk (_stream_readable.js:263:12)
    at readableAddChunk (_stream_readable.js:250:11)
    at Socket.Readable.push (_stream_readable.js:208:10)

example.js file:

/*jshint node:true*/
'use strict';

var ari = require('ari-client');
var util = require('util');

ari.connect('http://localhost:8088', 'asterisk', 'asterisk', clientLoaded);

// handler for client being loaded
function clientLoaded (err, client) {
  if (err) {
    throw err;
  }

  client.channels.list(function(err, channels) {
    if (!channels.length) {
      console.log('No channels currently :-(');
    } else {
      console.log('Current channels:');
      channels.forEach(function(channel) {
        console.log(channel.name);
      });
    }
  });

  // handler for StasisStart event
  function stasisStart(event, channel) {
    console.log(util.format(
        'Channel %s has entered the application', channel.name));

    // use keys on event since channel will also contain channel operations
    Object.keys(event.channel).forEach(function(key) {
      console.log(util.format('%s: %s', key, JSON.stringify(channel[key])));
    });
  }

  // handler for StasisEnd event
  function stasisEnd(event, channel) {
    console.log(util.format(
        'Channel %s has left the application', channel.name));
  }

  client.on('StasisStart', stasisStart);
  client.on('StasisEnd', stasisEnd);

  client.start('channel-dump');
}

The output I get in asterisk console is as below:

<--- Sending ARI response to 127.0.0.1:33728 --->
404 Not Found
<--- ARI request received from: 127.0.0.1:33728 --->
Connection: Upgrade
Upgrade: websocket
Content-type: application/json
Host: localhost:8088
{
Sec-WebSocket-Version: 13
  "message": "Resource not found"
Sec-WebSocket-Key: MTMtMTU0MTg3ODcyMTY1MA==
}
Sec-WebSocket-Extensions: permessage-deflate; client_max_window_bits

app: channel-dump
api_key: asterisk:asterisk
body:


<--- Sending ARI response to 127.0.0.1:33728 --->
404 Not Found
Content-type: application/json
{
  "message": "Resource not found"
}

Sandeep-PC*CLI> 

my extension.conf contains:

[default]

exten => 1000,1,NoOp()
        same => n,Answer()
        same => n,Playback(hello-world)
        same => n,Stasis(channel-dump)
        same => n,Hangup()