Repository: librenms/librenms (language: php)

Issue:
Graph error.
### The problem

PR "New graph design for health sensors again #16858" caused an issue with displaying charts in notifications.
As a test, I returned the "dbm.inc.php" file to the "/opt/librenms/includes/html/graphs/sensor/" folder and the graphs started to display correctly. Please re-examine the PR.

### Output of ./validate.php

```txt
===========================================
Component | Version
--------- | -------
LibreNMS  | 24.11.0-116-g0905d562a (2024-12-19T07:55:12+01:00)
DB Schema | 2024_10_24_131715_mpls_sdp_bindings_enum_string (310)
PHP       | 8.3.11
Python    | 3.12.3
Database  | MariaDB 10.11.8-MariaDB-0ubuntu0.24.04.1
RRDTool   | 1.7.2
SNMP      | 5.9.4.pre2
===========================================

[OK]    Composer Version: 2.8.3
[OK]    Dependencies up-to-date.
[OK]    Database connection successful
[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]    Distributed Polling setting is enabled globally
[OK]    Connected to rrdcached
[OK]    Active pollers found
[OK]    Dispatcher Service is enabled
[OK]    Locks are functional
[OK]    Python wrapper cron entry is not present
[OK]    Redis is functional
[WARN]  IPv6 is disabled on your server, you will not be able to add IPv6 devices.
[OK]    rrdtool version ok
[OK]    Connected to rrdcached
[WARN]  Your local git contains modified files, this could prevent automatic updates.
        [FIX]:
        You can fix this with ./scripts/github-remove
        Modified Files:
         includes/html/graphs/sensor/auth.inc.php
         includes/html/graphs/sensor/power_consumed.inc.php
```


### What was the last working version of LibreNMS?

24.11.0

### Anything in the logs that might be useful for us?

```txt
.
```



Discussion / hints:
Thank you for your report. I have not tested because I have never used graphs in mails, but this might solve the problem. The graphs are generated in a thousand places. I think we should work on centralizing the RRD Graph gernerators in general.


```
in LibreNMS/Util/Graph.php  from line 155 there is another elseif necessary I think.

        if (is_customoid_graph($type, $subtype)) {
            $unit = $vars['unit'];
            require base_path('/includes/html/graphs/customoid/customoid.inc.php');
        } elseif (is_file(base_path("/includes/html/graphs/$type/$subtype.inc.php"))) {
            require base_path("/includes/html/graphs/$type/$subtype.inc.php");
+        } elseif (is_file(base_path("/includes/html/graphs/$type/generic.inc.php"))) {
+            require base_path("/includes/html/graphs/$type/generic.inc.php");
        } else {
            throw new RrdGraphException("{$type}_$subtype template missing", "{$type}_$subtype missing", $width, $height);
        }

```
> Thank you for your report. I have not tested because I have never used graphs in mails, but this might solve the problem. The graphs are generated in a thousand places. I think we should work on centralizing the RRD Graph gernerators in general.
> 
> ```
> in LibreNMS/Util/Graph.php  from line 155 there is another elseif necessary I think.
> 
>         if (is_customoid_graph($type, $subtype)) {
>             $unit = $vars['unit'];
>             require base_path('/includes/html/graphs/customoid/customoid.inc.php');
>         } elseif (is_file(base_path("/includes/html/graphs/$type/$subtype.inc.php"))) {
>             require base_path("/includes/html/graphs/$type/$subtype.inc.php");
> +        } elseif (is_file(base_path("/includes/html/graphs/$type/generic.inc.php"))) {
> +            require base_path("/includes/html/graphs/$type/generic.inc.php");
>         } else {
>             throw new RrdGraphException("{$type}_$subtype template missing", "{$type}_$subtype missing", $width, $height);
>         }
> ```

I will test tomorrow, thank you ;)
Does it help? If you can confirm I will fix with PR.
> Does it help? If you can confirm I will fix with PR.

Yes it's works ;)

Fix patch:
diff --git a/LibreNMS/Util/Graph.php b/LibreNMS/Util/Graph.php
index bea92d7e1d00..ee56981684f0 100644
--- a/LibreNMS/Util/Graph.php
+++ b/LibreNMS/Util/Graph.php
@@ -157,6 +157,8 @@ public static function get($vars): GraphImage
             require base_path('/includes/html/graphs/customoid/customoid.inc.php');
         } elseif (is_file(base_path("/includes/html/graphs/$type/$subtype.inc.php"))) {
             require base_path("/includes/html/graphs/$type/$subtype.inc.php");
+        } elseif (is_file(base_path("/includes/html/graphs/$type/generic.inc.php"))) {
+            require base_path("/includes/html/graphs/$type/generic.inc.php");
         } else {
             throw new RrdGraphException("{$type}_$subtype template missing", "{$type}_$subtype missing", $width, $height);
         }


Test patch: