Alert Transport - API

Hello Team,

I have a ticketing system which can be accessed only by authenticating to it using cert and key.

I made below changes to Api.php file to add cert path and key path fields to the Alert Transport API GUI as shown.

I am trying to invoke ticketing system using this new API alert transport but I am getting error, when I do the same with CLI curl command with same cert and key I can successfully invoke our ticketing system to create a ticket.

what ever I am trying to do, is it supported? or am I doing something wrong.

ERROR:
Test to api failed
Transport delivery failed with 404 for : {“code”:“NotFound”,“errorCode”:null,“message”:"Unable to find workflow

MODIFIED CODE:

I’ve created a few custom transport to integrate with Slack Workflows and AWS Cloudwatch by simply adding a new transport class. I haven’t attempted to do what you’re doing here, but if you need to use mutual TLS, I’d probably create a new Transport as well (LibreNMS updates to Api.php will likely override your changes). Additionally, I’d suspect you’d have to invoke some php library as part of your $client to establish the mutual TLS handshake. It seems like you’ve just added fields here?

Thank you @ratkiewi.

I created new transport type Apicertauth.php and when I try to use it I get error. I troubleshooted a lot and found that I can trigger ticketing system using curl with cert and key files, also I create a php file (below) out of librenms system on the same server and tried executing and it was success.

But when I try to execute any files in Transport directory I get error at the class line. I just copied the contents of Api.php to Apicertauth.php, this new type shows up in GUI. validation is good even the dump-autoload looks good.

FAILED PHP:
root@SERVER:/opt/librenms/LibreNMS/Alert/Transport#
root@SERVER:/opt/librenms/LibreNMS/Alert/Transport# php Apicertauth.php

PHP Fatal error: Uncaught Error: Class “LibreNMS\Alert\Transport” not found in /opt/librenms/LibreNMS/Alert/Transport/Apicertauth.php:10
Stack trace:
#0 {main}
thrown in /opt/librenms/LibreNMS/Alert/Transport/Apicertauth.php on line 10

root@SERVER:/opt/librenms/LibreNMS/Alert/Transport# php Ciscospark.php
PHP Fatal error: Uncaught Error: Class “LibreNMS\Alert\Transport” not found in /opt/librenms/LibreNMS/Alert/Transport/Ciscospark.php:20
Stack trace:
#0 {main}
thrown in /opt/librenms/LibreNMS/Alert/Transport/Ciscospark.php on line 20

root@SERVER:/opt/librenms/LibreNMS/Alert/Transport#

PHP FILE:

root@SERVER:/home/azureuser# cat testapicall.php

<?php $cert = "/path_to/cert.pem"; $key = "/path_to/key.pem"; $ch = curl_init(); curl_setopt($ch, CURLOPT_URL, "https://SOMEURL"); curl_setopt($ch, CURLOPT_POST, 1); curl_setopt($ch, CURLOPT_HTTPHEADER, ["Content-Type: application/json"]); curl_setopt($ch, CURLOPT_SSLCERT, $cert); curl_setopt($ch, CURLOPT_SSLKEY, $key); curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode(["details" => "Test"])); $response = curl_exec($ch); $http_code = curl_getinfo($ch, CURLINFO_HTTP_CODE); curl_close($ch); echo "Response Code: " . $http_code . "\n"; echo "Response: " . $response . "\n"; ?>

root@SERVER:/home/azureuser#

My PHP knowledge is quite limited and have never tried from command line invoking a transport. But I would think that you would need to test as user librenms (assuming you’re running it as librenms and not root) so that the Transport base class can be referenced? I usually just use the “Test” button in the UI to test my code.