VictorRobellini / pfSense-Dashboard

A functional and useful dashboard for pfSense that utilizes influxdb, grafana and telegraf
669 stars 184 forks source link

Issue with pfinterface.php #32

Closed Blekken closed 3 years ago

Blekken commented 3 years ago

hey guys, been using this for ages, updated to the new dashboard a week ago have noticed the following error resulting in no interface info being sent to influxdb;

2021-03-14T01:04:51Z E! [inputs.exec] Error in plugin: exec: exit status 255 for command '/usr/local/bin/telegraf_pfinterface.php':

have reimported the file from the repo - also checked permissions; however not sure what 255 exist status refers to.. (google fails me)

any ideas?

VictorRobellini commented 3 years ago

https://github.com/VictorRobellini/pfSense-Dashboard#telegraf-plugins

Have you tried running it from a pfsense terminal?

You can run most plugins from a shell/ssh session to verify the output. (the environment vars may be differet when telegraf is executing the plugin)

If you're copying from a windows system, check clrf

If you're copying from a windows system, make sure the CRLF is correct

Blekken commented 3 years ago

Hi Victor,

apologies should have clarified, this is the error directly from the shell session from the following cmd;

telegraf --test --config /usr/local/etc/telegraf.conf

VictorRobellini commented 3 years ago

What happens when you run it outside of telegraf?
[2.5.0-RELEASE][admin@pfSense.myhous.com]/root: /usr/local/bin/telegraf_pfinterface.php

Did you check clrf?
cat -e /usr/local/bin/telegraf_pfinterface.php

This should display unix line endings (\n or LF) as $ and Windows line endings (\r\n or CRLF) as ^M$.

Blekken commented 3 years ago

Thanks Victor;

here is the output for both

[21.02-RELEASE][root@pfsense]/root: /usr/local/bin/telegraf_pfinterface.php
No input file specified.
[21.02-RELEASE][root@pfsense]/root: cat -e /usr/local/bin/telegraf_pfinterface.php
#!/usr/local/bin/php-cgi -f^M$
<?php^M$
require_once("config.inc");^M$
require_once("gwlb.inc");^M$
require_once("interfaces.inc");^M$
^M$
$host = gethostname();^M$
$source = "pfconfig";^M$
^M$
$iflist = get_configured_interface_with_descr(true);^M$
foreach ($iflist as $ifname => $friendly) {^M$
        $ifinfo =  get_interface_info($ifname);^M$
        $ifstatus = $ifinfo['status'];^M$
        $ifconf = $config['interfaces'][$ifname];^M$
        $ip4addr = get_interface_ip($ifname);^M$
        $ip4subnet = get_interface_subnet($ifname);^M$
        $ip6addr = get_interface_ipv6($ifname);^M$
        $ip6subnet = get_interface_subnetv6($ifname);^M$
        $realif = get_real_interface($ifname);^M$
        $mac = get_interface_mac($realif);^M$
^M$
        if (!isset($ip4addr)){^M$
                $ip4addr = "Unassigned";^M$
        }^M$
        if (!isset($ip4subnet)){^M$
            $ip4subnet = "Unassigned"; ^M$
        }^M$
        if (!isset($ip6addr)){^M$
            $ip6addr = "Unassigned";^M$
        }^M$
        if (!isset($ip6subnet)){^M$
            $ip6subnet = "Unassigned"; ^M$
        }^M$
        if (!isset($mac)){^M$
                $mac = "Unavailable";^M$
        }^M$
        if (strtolower($ifstatus) == "up"){^M$
                $ifstatus = 1;^M$
        }^M$
        if (strtolower($ifstatus) == "active"){^M$
                $ifstatus = 1;^M$
        }^M$
        if (strtolower($ifstatus) == "no carrier"){^M$
                $ifstatus = 0;^M$
        }^M$
        if (strtolower($ifstatus) == "down"){^M$
                $ifstatus = 0;^M$
        }^M$
        if (!isset($ifstatus)){^M$
                $ifstatus = 2;^M$
        }   ^M$
^M$
        printf("interface,host=%s,name=%s,ip4_address=%s,ip4_subnet=%s,ip6_address=%s,ip6_subnet=%s,mac_address=%s,friendlyname=%s,source=%s status=%s\n",^M$
                $host,^M$
                $realif,^M$
                $ip4addr,^M$
                $ip4subnet,^M$
                $ip6addr,^M$
                $ip6subnet,^M$
                $mac,^M$
                $friendly,^M$
                $source,^M$
                $ifstatus^M$
                );^M$
}^M$
?>^M$
[21.02-RELEASE][root@pfsense]/root:
dennypage commented 3 years ago

You have carriage returns (indicated by the '^M') in the file. This is the crlf issue that Victor referred to in his first response. This comes from creating/editing the file on Windows before sending it to a unix system.

You need to recreate the file without the carriage returns. See the "make sure the CRLF is correct" link above for additional instructions.

VictorRobellini commented 3 years ago

@dennypage is correct. This is already documented on the main README and linked in this thread with additional information.

Solution: Read the docs