APC Status Widget
-
Here is the screen shots of what they should look like
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>
<?phpForgive me if posting this is wrong. New to the site and usage.
Thank you. -
@carver said in APC Status Widget:
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 -
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:
Regards,
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?
-
@carver said in APC Status Widget:
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 -
-
@fireodo
It doesn't work on my machine. Widget is displayed but not values. Correction, it does work.......grin -
@carver said in APC Status Widget:
@fireodo
It doesn't work on my machine. Widget is displayed but not values. Correction, it does work.......grinNow, 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 -
@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.......grinCarver
-
@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.......grinCarver
-
@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........grinCarver
-
@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 -
This post is deleted!