Alerting - New API-based transport towards local SMS-gateway giving me POST PARAMS missing

Trying to do an integration to a SMS provider and using the standard API form in Alert Transports.

Tested using curl, and everything works, but cannot seem to get my head around the structure when defining the API Transport.

So - This works:
curl -X POST -H “Authorization: Basic auth-string==” -d ’
{
“to”:“MYPHONE”, “message”: “This is the message text body”, “from”: “SMS-GATEWAY”
}
’ "https://api.cpsms.dk/v2/send

When building this, I just paste that string into the body field.

In librenms.log, I get this error:
{“code”:400,“message”:“POST parameters is missing”}

Any takers??

Looking at Api.php.

Here: https://github.com/librenms/librenms/blob/master/LibreNMS/Alert/Transport/Api.php

Would I be correct in assuming that the body will not accept JSON??

Hi
I think the issue is simpler than this. BODY is not transmitted at all when the request is a POST request. Only for PUT we can see it. So you may try to add this at line 87:

$request_opts['body'] = $body;

And see if you can get the expected result.

Bye

Hi @Jens_Nykaer,
Did you manage to make it work? I am struggling with the same thing.
I manage to put the line in Api.php as suggested by @PipoCanaja and add the xml content in the body field, but the problem is that Libre is not resolving the variables in there:


In Spectrum:
image

Fixed it by changing the Api.php file:

        } else { //Method POST
        $request_opts['query'] = $query;
        foreach ($query as $metric => $value) { // replace all variables defined in Options for and found in Body for their values
            $body = str_replace( '$' . $metric, "$value" , $body);
        }
        // file_put_contents('/tmp/new_body.txt',print_r($body,true));
        $request_opts['body'] = $body;
        $res = $client->request('POST', $host, $request_opts);
    }

@mzacchi
Please open a pull request to share your change with everybody (and ensure it won’t be broken with an upgrade later on).

Done, sorry for that. :slight_smile:

@PipoCanaja I have raised the Pull request, but some checks have failed. GitHub - mzacchi/librenms at mzacchi-patch-api_transport
What do I do if it is beyond me to understand what could be wrong?

Just open it on the official repository so we can review it and merge it :
https://github.com/librenms/librenms/pulls

Now I got it, thanks.

This topic was automatically closed 186 days after the last reply. New replies are no longer allowed.