Alert Rules and Alert Transports pages seem to be broken

Going to the alert rules or alert transport pages gives a very plain looking page and the browser says some page is missing. Maybe the page is missing its scripts or something like that? Anyway, the pages basically appear non-functional.

This happened on both of my installations. Validation checks out OK, and these systems have been running fine for months.

Maybe once this is resolved I need to change my update frequency from daily to monthly, because this is a bit unsettling. I’m assuming it’s related to a recent update?

Thoughts?

Thanks in advance for any insights.

Validation Output
===========================================
Component | Version
--------- | -------
LibreNMS  | 23.5.0-4-g0c9313258 (2023-05-24T08:24:05-05:00)
DB Schema | 2023_05_12_071412_devices_expand_timetaken_doubles (251)
PHP       | 8.1.2-1ubuntu2.11
Python    | 3.10.6
Database  | MariaDB 10.6.12-MariaDB-0ubuntu0.22.04.1
RRDTool   | 1.7.2
SNMP      | 5.9.1
===========================================

[OK]    Composer Version: 2.5.5
[OK]    Dependencies up-to-date.
[OK]    Database connection successful
[OK]    Database Schema is current
[OK]    SQL Server meets minimum requirements
[OK]    lower_case_table_names is enabled
[OK]    MySQL engine is optimal
[OK]    Database and column collations are correct
[OK]    Database schema correct
[OK]    MySQl and PHP time match
[OK]    Active pollers found
[OK]    Dispatcher Service not detected
[OK]    Locks are functional
[OK]    Python poller wrapper is polling
[OK]    Redis is unavailable
[OK]    rrd_dir is writable
[OK]    rrdtool version ok

It has been fixed 1 hour ago (see. here), can you please run ./daily.sh again?

1 Like

Thanks, but if you mean this one (via running daily.sh):

Updated from 075267dcc to 0c9313258 OK

I already did that before I created this topic.

Running daily update again didn’t change it. (Behavior is the same, and it didn’t mention updating as shown above.)

I tried restarting Apache. I tried rebooting Linux. I tried a different browser to see if it would be related to the browser cache, but to no avail.

Web Page Images


pagefail2

Bizarre. I would look at the logs/librenms.log file for errors and post it here if you have one.

Yes, sorry for the confusion. I got it working now.

It was my custom transport code which needed updates. See below. I don’t really use PHP that much; I suppose I know just enough to be dangerous. :wink:

Thanks again.

Custom Nextcloud Transport Code (fixed)
<?php
/**
 * LibreNMS Nextcloud Talk alerting transport
 * 
 * Copyright (c) 2023 Dan Mahn
 * 
 * Permission is hereby granted, free of charge, to any person obtaining a copy
 * of this software and associated documentation files (the "Software"), to deal
 * in the Software without restriction, including without limitation the rights
 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
 * copies of the Software, and to permit persons to whom the Software is
 * furnished to do so.
 * 
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
 * SOFTWARE.
 */

namespace LibreNMS\Alert\Transport;

use LibreNMS\Alert\Transport;
use LibreNMS\Exceptions\AlertTransportDeliveryException;

class Nextcloudtalk extends Transport
{
    protected string $name = 'Nextcloud Talk';

    public function deliverAlert(array $alert_data): bool
    {
        $link     = $this->config['nextcloudtalk-link'];
        $username = $this->config['nextcloudtalk-username'];
        $password = $this->config['nextcloudtalk-password'];

        return $this->contactNextcloudtalk($alert_data, $link, $username, $password);
    }

    public static function contactNextcloudtalk(array $alert_data, $link, $username, $password)
    {

        $json_data = [
            'message' => strip_tags($alert_data['msg']),
        ];
        $json_payload = json_encode($json_data);

        $callapi = ['/index.php/call/', '/call/'];
        $chatapi = '/ocs/v2.php/apps/spreed/api/v1/chat/';
        $url = str_replace($callapi, $chatapi, $link);

        // cURL resource ...
        $ch = curl_init($url);

        curl_setopt($ch, CURLOPT_POSTFIELDS, $json_payload);
        curl_setopt($ch, CURLOPT_HTTPHEADER, ['Content-Type:application/json', 'OCS-APIRequest: true']);
        curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
        curl_setopt($ch, CURLOPT_USERPWD, "$username:$password");

        // POST request
        $result = curl_exec($ch);

        // Get result code
        $code = curl_getinfo($ch, CURLINFO_HTTP_CODE);

        // ... cURL resource
        curl_close($ch);

        if ($code != 201) {
            $data = [
                'title' => 'LibreNMS alert for: ' . $alert_data['hostname'],
                'description' => $alert_data['msg'],
            ];
            throw new AlertTransportDeliveryException(
                    $alert_data, 
                    $code, 
                    'Conversation Token ' . current(array_reverse(explode('/',$url))), 
                    $alert_data['msg'], 
                    $data);
        }

        return true;
    }


    public static function configTemplate(): array
    {
        return [
            'config' => [
                [
                    'title' => 'Conversation Link',
                    'name' => 'nextcloudtalk-link',
                    'descr' => 'Nextcloud conversation link, e.g. https://cloud.somewhere.tld/call/{token}',
                    'type' => 'text'
                ],
                [
                    'title' => 'Username',
                    'name' => 'nextcloudtalk-username',
                    'descr' => 'Nextcloud username',
                    'type' => 'text',
                ],
                [
                    'title' => 'App Password',
                    'name' => 'nextcloudtalk-password',
                    'descr' => 'Nextcloud app password',
                    'type' => 'password',
                ],
            ],
            'validation' => [
                'nextcloudtalk-link' => 'required|string',
                'nextcloudtalk-username' => 'required|string',
                'nextcloudtalk-password' => 'required|string',
            ],
        ];
    }
}

1 Like

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