Netgate Discussion Forum
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Search
    • Register
    • Login

    APC Status Widget

    Scheduled Pinned Locked Moved pfSense Packages
    15 Posts 3 Posters 1.4k Views
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • C
      Carver
      last edited by

      I am in the process of creating a widget for the APC UPS package but I am needing some help. This is the first time i have ever coded anything web related. I have been working on this for a couple of years on and off again. If you would like to review my code and fix/repair/code correctly I would appreciate it very much. The online status of the widget works correctly but the offline code does not.
      COMMLOST should be under the status header and the other items I don't want displayed, just COMMLOST.

      [0_1610849122909_apc_status.widget.php](Uploading 100%)
      [0_1610849142880_apc_status.inc](Uploading 100%)

      fireodoF 1 Reply Last reply Reply Quote 0
      • fireodoF
        fireodo @Carver
        last edited by

        @carver
        Hi,

        the 2 files you have uploaded are not reacheable ๐Ÿ˜•

        Have a fine Sunday,
        fireodo

        Kettop Mi4300YL CPU: i5-4300Y @ 1.60GHz RAM: 8GB Ethernet Ports: 4
        SSD: SanDisk pSSD-S2 16GB (ZFS) WiFi: WLE200NX
        pfsense 2.7.2 CE
        Packages: Apcupsd Cron Iftop Iperf LCDproc Nmap pfBlockerNG RRD_Summary Shellcmd Snort Speedtest System_Patches.

        C 1 Reply Last reply Reply Quote 0
        • C
          Carver @fireodo
          last edited by

          @fireodo

          Here is the screen shots of what they should look like

          80819e3c-f366-4a37-9534-cffa4d7e77be-image.png

          eac6ffa0-2fc7-460f-802f-1662f943a08a-image.png

          Code for apc_status_inc

          <?php
          /*

          • apc_status.inc
          • part of pfSense (https://www.pfsense.org)
          • Copyright (c) 2004-2020 Rubicon Communications, LLC (Netgate)
          • All rights reserved.
          • Licensed under the Apache License, Version 2.0 (the "License");
          • you may not use this file except in compliance with the License.
          • You may obtain a copy of the License at
          • http://www.apache.org/licenses/LICENSE-2.0
          • Unless required by applicable law or agreed to in writing, software
          • distributed under the License is distributed on an "AS IS" BASIS,
          • WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
          • See the License for the specific language governing permissions and
          • limitations under the License.
            */

          //set variable for custom title
          $apc_status_title = "APC Status";
          $apc_status_title_link = "apc_status.php";

          /* Build database */
          unset($apcstatus);
          $instruction = "apcaccess -h 0.0.0.0:3551";
          $result = shell_exec($instruction);
          $apcstatus = explode("\n",$result);

          /* Checking the status of UPS communication */
          $stat = substr($apcstatus[10], -7 );
          if ($stat = "ONLINE") {

          /* display online status */
          $stat = substr($apcstatus[10], -7);
          $model = substr($apcstatus[9], -9);
          $linev = substr($apcstatus[11], 10, -5);
          $battv = substr($apcstatus[22], 10, -5);

          } else {
          /* display offline status */
          $stat = "COMMLOST";
          $model = "";
          $linev = "";
          $battv = "";

          }
          ?>

          Code for apc_widget_php

          <?php
          /*

          • apc_status.php
          • A widget developed by John Van Winkle to monitor the status of my APC UPS.
          • Copyright (c) 2018 John Van Winkle
          • All rights reserved.
          • Licensed under the Apache License, Version 2.0 (the "License");
          • you may not use this file except in compliance with the License.
          • You may obtain a copy of the License at
          • http://www.apache.org/licenses/LICENSE-2.0
          • Unless required by applicable law or agreed to in writing, software
          • distributed under the License is distributed on an "AS IS" BASIS,
          • WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
          • See the License for the specific language governing permissions and
          • limitations under the License.
            */

          require_once("guiconfig.inc");
          require_once("pfsense-utils.inc");
          require_once("/usr/local/pkg/apcupsd.inc");

          /* Build table to display data */
          ?>
          <div class="table-responsive">
          <table class="table table-striped table-hover table-condensed">
          <thead>
          <tr>
          <th>UPS Status</th>
          <th>Back UPS</th>
          <th>Line Volts</th>
          <th>Battery Volts</th>
          </tr>
          </thead>
          <tr>
          <td><font color=green><?=$stat?></td>
          <td><font color=blue><?=$model?></td>
          <td><?=$linev?></td>
          <td><?=$battv?></td>
          </tr>
          </table>
          </div>
          <?php

          Forgive me if posting this is wrong. New to the site and usage.
          Thank you.

          fireodoF 1 Reply Last reply Reply Quote 0
          • fireodoF
            fireodo @Carver
            last edited by

            @carver said in APC Status Widget:

            @fireodo

            Hi,

            Here is the screen shots of what they should look like

            I'm not a Code Specialist but as far as I can understand in the moment the UPS is Offline there is no output on the "apcaccess -h 0.0.0.0:3551" command so there is no possibility for the script to read the UPS Name and also any other parameter - maybe thats why the script gets confused.

            I hope that one of the Coders from this forum is looking
            at your code and maybe find a better solution for the "communication lost" situation.

            Forgive me if posting this is wrong. New to the site and usage.

            Everybody is somewhere somehow a beginner ...

            Thank you.
            You're welcome!

            Good start into the week,
            fireodo

            Kettop Mi4300YL CPU: i5-4300Y @ 1.60GHz RAM: 8GB Ethernet Ports: 4
            SSD: SanDisk pSSD-S2 16GB (ZFS) WiFi: WLE200NX
            pfsense 2.7.2 CE
            Packages: Apcupsd Cron Iftop Iperf LCDproc Nmap pfBlockerNG RRD_Summary Shellcmd Snort Speedtest System_Patches.

            1 Reply Last reply Reply Quote 1
            • fireodoF
              fireodo
              last edited by fireodo

              Hi,

              I have customized your script for my UPS (APC Back-UPS CS 350) and for my native language (german).
              See here:
              apc_status.widget.php

              <?php
              /*
              
              apc_status.php
              A widget developed by John Van Winkle to monitor the status of my APC UPS.
              Copyright (c) 2018 John Van Winkle
              All rights reserved.
              Licensed under the Apache License, Version 2.0 (the "License");
              you may not use this file except in compliance with the License.
              You may obtain a copy of the License at
              http://www.apache.org/licenses/LICENSE-2.0
              Unless required by applicable law or agreed to in writing, software
              distributed under the License is distributed on an "AS IS" BASIS,
              WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
              See the License for the specific language governing permissions and
              limitations under the License.
              */
              require_once("guiconfig.inc");
              require_once("pfsense-utils.inc");
              require_once("/usr/local/pkg/apcupsd.inc");
              
              /* Build table to display data */
              ?>
              
              <meta http-equiv="refresh" content="900" >
              
              <div class="table-responsive">
              <table class="table table-striped table-hover table-condensed">
              <thead>
              <tr>
              <th>Status</th>
              <th>Modell</th>
              <th>Netz</th>
              <th>Last</th>
              <th>Laufzeit</th>
              <th>Batterie</th>
              </tr>
              </thead>
              <tr>
              <td><font color=limegreen><?=$stat?></td>
              <td><font color=cyan><?=$model?></td>
              <td><?=$linev?> V</td>
              <td><?=$load?> %</td>
              <td><?=$time?> min.</td>
              <td><font color=yellow><?=$batt?> sek.</td>
              </tr>
              </table>
              </div>
              <?php
              

              apc_status.inc

              <?php
              /*
              
              apc_status.inc
              part of pfSense (https://www.pfsense.org)
              Copyright (c) 2004-2020 Rubicon Communications, LLC (Netgate)
              All rights reserved.
              Licensed under the Apache License, Version 2.0 (the "License");
              you may not use this file except in compliance with the License.
              You may obtain a copy of the License at
              http://www.apache.org/licenses/LICENSE-2.0
              Unless required by applicable law or agreed to in writing, software
              distributed under the License is distributed on an "AS IS" BASIS,
              WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
              See the License for the specific language governing permissions and
              limitations under the License.
              */
              //set variable for custom title
              $apc_status_title = "APC Status";
              $apc_status_title_link = "apcupsd_status.php";
              
              /* Build database */
              unset($apcstatus);
              $instruction = "apcaccess -h 0.0.0.0:3551";
              $result = shell_exec($instruction);
              $apcstatus = explode("\n",$result);
              
              /* Checking the status of UPS communication */
              $stat = substr($apcstatus[10], -7 );
              if ($stat = "ONLINE") {
              
              /* display online status */
              $stat = substr($apcstatus[10], -7);
              $model = substr($apcstatus[4], -7);
              $linev = substr($apcstatus[11], 10, -5);
              $load = substr($apcstatus[12], 10, -7);
              $time = substr($apcstatus[14], 10, -8);
              $batt = substr($apcstatus[31], 10, -8);
              
              } else {
              /* display offline status */
              $stat = "COMMLOST";
              $model = "";
              $linev = "";
              $load = "";
              $time = "";
              $batt = "";
              
              }
              ?>
              

              Looks like here:
              pfsense65.png.jpg

              Regards,
              fireodo

              Kettop Mi4300YL CPU: i5-4300Y @ 1.60GHz RAM: 8GB Ethernet Ports: 4
              SSD: SanDisk pSSD-S2 16GB (ZFS) WiFi: WLE200NX
              pfsense 2.7.2 CE
              Packages: Apcupsd Cron Iftop Iperf LCDproc Nmap pfBlockerNG RRD_Summary Shellcmd Snort Speedtest System_Patches.

              C 1 Reply Last reply Reply Quote 0
              • C
                Carver @fireodo
                last edited by Carver

                @fireodo

                Thank you for the correction to the code. I was not sure if it was correct or if there was a more correct way to code it. I will check it out on my system. How does it work with loss of communication?

                fireodoF 2 Replies Last reply Reply Quote 0
                • fireodoF
                  fireodo @Carver
                  last edited by

                  @carver said in APC Status Widget:

                  @fireodo

                  Thank you for the correction to the code.

                  Its only a adaptation on my personal UPS - the results are diferite depending on the UPS that is utilized (the output of "apcaccess -h 0.0.0.0:3551" vary from UPS to UPS)

                  I will check it out on my system.

                  You probably will have to make some corrections. The refresh of the widget is also something that can have some improvements.

                  How does it work with loss of communication?

                  No, I couldn't do it here ... sorry!

                  Regards,
                  fireodo

                  Kettop Mi4300YL CPU: i5-4300Y @ 1.60GHz RAM: 8GB Ethernet Ports: 4
                  SSD: SanDisk pSSD-S2 16GB (ZFS) WiFi: WLE200NX
                  pfsense 2.7.2 CE
                  Packages: Apcupsd Cron Iftop Iperf LCDproc Nmap pfBlockerNG RRD_Summary Shellcmd Snort Speedtest System_Patches.

                  1 Reply Last reply Reply Quote 0
                  • fireodoF
                    fireodo @Carver
                    last edited by

                    @carver

                    Hello,

                    look what I have found:

                    APC-Status Widget

                    Regards,
                    fireodo

                    Kettop Mi4300YL CPU: i5-4300Y @ 1.60GHz RAM: 8GB Ethernet Ports: 4
                    SSD: SanDisk pSSD-S2 16GB (ZFS) WiFi: WLE200NX
                    pfsense 2.7.2 CE
                    Packages: Apcupsd Cron Iftop Iperf LCDproc Nmap pfBlockerNG RRD_Summary Shellcmd Snort Speedtest System_Patches.

                    C 1 Reply Last reply Reply Quote 0
                    • C
                      Carver @fireodo
                      last edited by Carver

                      @fireodo
                      It doesn't work on my machine. Widget is displayed but not values. Correction, it does work.......grin

                      fireodoF 1 Reply Last reply Reply Quote 0
                      • fireodoF
                        fireodo @Carver
                        last edited by fireodo

                        @carver said in APC Status Widget:

                        @fireodo
                        It doesn't work on my machine. Widget is displayed but not values. Correction, it does work.......grin

                        ๐Ÿ˜Š Now, if you look at the code, you can maybe make modifications to customize the widget for your personal needs ... and perhaps you can also test the "COMMLOST" - scenario.
                        If you want I can sent you my customized version and you can compare it with the original so you can see where you can make customizations.

                        Regards,
                        fireodo

                        Kettop Mi4300YL CPU: i5-4300Y @ 1.60GHz RAM: 8GB Ethernet Ports: 4
                        SSD: SanDisk pSSD-S2 16GB (ZFS) WiFi: WLE200NX
                        pfsense 2.7.2 CE
                        Packages: Apcupsd Cron Iftop Iperf LCDproc Nmap pfBlockerNG RRD_Summary Shellcmd Snort Speedtest System_Patches.

                        C 1 Reply Last reply Reply Quote 0
                        • C
                          Carver @fireodo
                          last edited by

                          @fireodo
                          I was thinking about customizing it for my tastes. It's a nice piece of code and works great with both scenarios, online and commlost. Yes, if you would like to send me yours, that will be great.......grin

                          Carver

                          fireodoF 1 Reply Last reply Reply Quote 0
                          • fireodoF
                            fireodo @Carver
                            last edited by

                            @carver said in APC Status Widget:

                            @fireodo
                            I was thinking about customizing it for my tastes. It's a nice piece of code and works great with both scenarios, online and commlost. Yes, if you would like to send me yours, that will be great.......grin

                            Carver

                            apc_usv.widget.zip

                            โ˜บ

                            Kettop Mi4300YL CPU: i5-4300Y @ 1.60GHz RAM: 8GB Ethernet Ports: 4
                            SSD: SanDisk pSSD-S2 16GB (ZFS) WiFi: WLE200NX
                            pfsense 2.7.2 CE
                            Packages: Apcupsd Cron Iftop Iperf LCDproc Nmap pfBlockerNG RRD_Summary Shellcmd Snort Speedtest System_Patches.

                            C 1 Reply Last reply Reply Quote 0
                            • C
                              Carver @fireodo
                              last edited by

                              @fireodo
                              Thanks for sending yours. I changed his original to the info I wanted to see on my firewall. I am going to try and test it today and make sure all aspects of it work. It is obvious after looking at his coding I donโ€™t have a clue what I am doing. I am too old school........grin

                              Carver

                              fireodoF 1 Reply Last reply Reply Quote 0
                              • fireodoF
                                fireodo @Carver
                                last edited by

                                @carver said in APC Status Widget:

                                @fireodo
                                Thanks for sending yours.

                                You're welcome!

                                I changed his original to the info I wanted to see on my firewall. I am going to try and test it today and make sure all aspects of it work. It is obvious after looking at his coding I donโ€™t have a clue what I am doing. I am too old school........grin

                                In fact its important that you get what you want! ๐Ÿ˜Š

                                Regards,
                                fireodo

                                Kettop Mi4300YL CPU: i5-4300Y @ 1.60GHz RAM: 8GB Ethernet Ports: 4
                                SSD: SanDisk pSSD-S2 16GB (ZFS) WiFi: WLE200NX
                                pfsense 2.7.2 CE
                                Packages: Apcupsd Cron Iftop Iperf LCDproc Nmap pfBlockerNG RRD_Summary Shellcmd Snort Speedtest System_Patches.

                                1 Reply Last reply Reply Quote 0
                                • occamsrazorO
                                  occamsrazor
                                  last edited by

                                  This post is deleted!
                                  1 Reply Last reply Reply Quote 0
                                  • First post
                                    Last post
                                  Copyright 2025 Rubicon Communications LLC (Netgate). All rights reserved.