All pastes #2068389 Raw Edit

APC Functions

public php v1 · immutable
#2068389 ·published 2011-05-24 13:47 UTC
rendered paste body
// APC Functions// Get Port Statusfunction apcGetStatus($APCip, $APCport, $community) {    $APCresponse = snmpget($APCip, $community, "1.3.6.1.4.1.318.1.1.12.3.3.1.1.4.$APCport", 1000000);    $APCresponse = str_replace('INTEGER: ', '', $APCresponse);    switch ($APCresponse) {        case '1':            $returnVal = 'On';            break;        case '2':            $returnVal = 'Off';            break;        case '3':            $returnVal = 'Reboot';            break;        case '4':            $returnVal = 'Unknown';            break;        case '5':            $returnVal = 'On with delay';            break;        case '6':            $returnVal = 'Off with delay';            break;        case '7':            $returnVal = 'Reboot with delay';            break;        default:            $returnVal = $APCresponse;    }    return $returnVal;}// Get all port statusesfunction apcGetStatusA($APCip, $community) {    $APCresponse = snmpwalk($APCip, $community, "1.3.6.1.4.1.318.1.1.12.3.3.1.1.4");    $APCresponse = str_replace('INTEGER: ', '', $APCresponse);    $APCresponse = str_replace('1', 'On', $APCresponse);    $APCresponse = str_replace('2', 'Off', $APCresponse);    $APCresponse = str_replace('3', 'Reboot', $APCresponse);    $APCresponse = str_replace('4', 'Unknown', $APCresponse);    $APCresponse = str_replace('5', 'On with delay', $APCresponse);    $APCresponse = str_replace('6', 'Off with delay', $APCresponse);    $APCresponse = str_replace('7', 'Reboot with delay', $APCresponse);    return $APCresponse;}// Set port statusfunction apcSetStatus($APCip, $APCport, $community, $rebootOption) {    switch ($rebootOption) {        case '1':            $actionTo = 'On';            break;        case '2':            $actionTo = 'Off';            break;        case '3':            $actionTo = 'Reboot';            break;        case '5':            $actionTo = 'On with delay';            break;        case '6':            $actionTo = 'Off with delay';            break;        case '7':            $actionTo = 'Reboot with delay';            break;        default:            return 'Invalid reboot option';    }    $actionFrom = apcGetStatus($APCip, $APCport, $community);    if (snmpset($APCip, $community, "1.3.6.1.4.1.318.1.1.12.3.3.1.1.4.$APCport", 'i', $rebootOption, 2000000)) {        $returnVal = "Actioned:$actionFrom to $actionTo";    } else {        $returnVal = "Failed to Action:$actionFrom to $actionTo";    }    return $returnVal;}