Re: Server Blog
Posted: Wed Apr 01, 2015 5:50 pm
Margaritas!
Nissan diesel engines, and the people who love them
https://nissandiesel.dyndns.org/
Too many of us invested too much of ourselves to not keep it around as a resource.goglio704 wrote:Al,
Thanks again for this forum. I have not been much of a participant the last few years, but it is nice to know the resource is out there.
Sumbitch. I wonder when that happened? I've gotta fix that ASAP.I don't see the Paypal donate button anymore.
Yup, since like 1993.Is your email still the same?
I've put together and implemented a way to programmatically get the APC MasterSwitchPlus to power cycle the outlet into which the cable modem is plugged, and I've added the script as a cron job to execute at the same time as a scheduled reboot of the Apache web daemon httpd (ie at 0001 PST every morning).After a while, the inbound http requests do not make it to the server. It seems to be an issue with the ISP. Power-cycling the cable modem restores this.
I'm looking into implementing an automated power cycle on that modem. It's plugged into an APC MasterSwitch, and I need to look at that unit's management console to see if scheduled power cycling is an option.
Code: Select all
<?php
/*
Created: 12Oct2015 ALS
Revised: 16Oct2015 ALS
PHP code to reboot an outlet on AP9225 w/AP9617 management card. Probably works OK with other NMCs such as AP9606, AP9618, AP9619.
Partly based around example code by apex at http://www.forked.net/forums/viewtopic.php?f=13&t=3490#p4131
Some documentation:
OID (Object ID) for MasterSwitch+ AP9225 = .1.3.6.1.4.1.318.1.1.6.5.1.1.5.1.1.
Defining the first bits:
1.3.6.1.4.1.318.1.1.6.5.1.1.5
iso . org . dod . internet . private . enterprises . apc . products . hardware . masterswitchMSP . sPDUOutletControlMSP . sPDUOutletControlMSPTable . sPDUOutletControlMSPEntry . sPDUOutletControlMSPOutletCommand
Getting this variable will return the outlet state. If the outlet is on, the immediateOnMSP (1) value will be returned.
If the outlet is off, the immediateOffMSP (3) value will be returned.
Setting this variable to:
immediateOnMSP (1) will immediately turn the outlet on.
delayedOnMSP (2) will turn the outlet on after the sPDUOutletConfigMSPPowerOnDelay OID time has elapsed.
immediateOffMSP (3) will immediately turn the outlet off.
gracefulRebootMSP (4) will cause the outlet to wait for device confirmation
(if applicable) and then turn the outlet off after the sPDUOutletConfigMSPPowerOffDelay
OID time has elapsed. The outlet will then turn on after the sPDUOutletConfigMSPRebootDuration OID time has elapsed.
immediateRebootMSP (5) will immediately reboot the outlet.
gracefulshutdownMSP (6) will cause the outlet to wait for device confirmation
(if applicable) and then turn the outlet off after the sPDUOutletConfigMSPPowerOffDelay OID time has elapsed.
The outlet will then turn on after the sum of the sPDUOutletConfigMSPRestartTime OID time and the
sPDUOutletConfigMSPPowerOnDelay OID time has elapsed.
overrideBatCapThreshMSP (7) will cause the outlet to ignore the Battery Capacity Threshold
and proceed waiting on the sPDUOutletConfigMSPPowerOnDelay OID time before turning the outlet on.
cancelPendingCommandMSP (8) will cause any pending command to this outlet to be cancelled.
For now, I do not know what the trailing ".1.1." mean.
*/
$oid = ".1.3.6.1.4.1.318.1.1.6.5.1.1.5.1.1." ; // AP9225
array_shift($argv); // Remove the first argument, which is always the script's name as called on the commandline.
echo "\r\n"; // Gain some separation from whatever may be on the screen.
if (empty($argv) || count($argv) != 4) { // Check for the correct number of commandline arguments.
echo "Incorrect number of arguments.\n";
echo "Usage: MSP_Control IP password outlet action \r\n";
echo "where:\r\n";
echo " IP = IP address (eg 192.168.0.52) \r\n";
echo " password = password for a SNMP account in the AP9225 that has write authority\r\n";
echo " outlet = integer that represents the outlet to be controlled (1..8)\r\n";
echo " action = integer that represents the action to be performed: \r\n";
echo " 1 = immediate power on \r\n";
echo " 2 = delayed power on \r\n";
echo " 3 = immediate power off \r\n";
echo " 4 = graceful reboot \r\n";
echo " 5 = immediate reboot \r\n";
echo " 6 = graceful power off delayed \r\n";
echo " 8 = cancel pending command \r\n";
exit(1); // End script; return a code for wrong arguments.
}
/* debug section
$host = "192.168.0.52" ; // My test AP9225
$community = "private" ; // Default password -- this should always be changed.
$outlet = "8" ; // My cable modem is plugged into outlet #8.
$action = "5" ; // 5 = reboot.
echo "var_dump after constants:\r\n";
echo var_dump($host, $community, $outlet, $action) . "\r\n";
*/
$host = (string)$argv[0];
$community = (string)$argv[1];
$outlet = (string)$argv[2];
$action = (string)$argv[3];
// Input validation checks. This should be enlarged/expanded/fleshed out if needed for robustness.
if ($outlet < 1 || $outlet > 8) { // Test for valid outlet number.
echo "Argument 'outlet' out of range.\r\n";
echo "Must be an integer from this set: [1, 2, 3, 4, 5, 6, 7, 8].\r\n";
exit(3);
}
$action_test = (int)$action; // Cast to int to test using numeric comparisons.
if ($action_test < 1 || $action_test == 7 || $action_test > 8) {
echo "Argument 'action' out of range.\r\n";
echo "Must be an integer from this set: [1, 2, 3, 4, 5, 6, 8].\r\n";
exit(4);
}
switch ($action) { // set up text for feedback later.
case 1:
$action_text = "immediate power on";
break;
case 2:
$action_text = "delayed power on";
break;
case 3:
$action_text = "immediate power off";
break;
case 4:
$action_text = "graceful reboot";
break;
case 5:
$action_text = "immediate reboot";
break;
case 6:
$action_text = "graceful power off then delayed power on";
break;
case 8:
$action_text = "cancel pending command";
break;
}
$returncode = snmpset($host, $community, $oid.$outlet , "i", $action) ;
// debug section
// echo "returncode = " . $returncode . "\r\n";
if ($returncode) {
echo "Succeeded: " . $action_text . " MasterSwitch+ outlet No. " . $outlet . ".\r\n";
exit(0);
}
else {
echo "Failed: " . $action_text . " MasterSwitch+ outlet No. " . $outlet . ".\r\n";
exit(2);
}
?>