Subversion Repositories ALCASAR

Rev

Rev 2976 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log

Rev 2976 Rev 3037
Line 38... Line 38...
38
     * get all information from all configured ups and store output in internal array
38
     * get all information from all configured ups and store output in internal array
39
     */
39
     */
40
    public function __construct()
40
    public function __construct()
41
    {
41
    {
42
        parent::__construct();
42
        parent::__construct();
-
 
43
        if (!defined('PSI_UPS_NUT_ACCESS')) {
-
 
44
             define('PSI_UPS_NUT_ACCESS', false);
-
 
45
        }
-
 
46
        switch (strtolower(PSI_UPS_NUT_ACCESS)) {
-
 
47
        case 'data':
43
        if (defined('PSI_UPS_NUT_LIST') && is_string(PSI_UPS_NUT_LIST)) {
48
            if (defined('PSI_UPS_NUT_LIST') && is_string(PSI_UPS_NUT_LIST)) {
44
            if (preg_match(ARRAY_EXP, PSI_UPS_NUT_LIST)) {
49
                if (preg_match(ARRAY_EXP, PSI_UPS_NUT_LIST)) {
45
                $upses = eval(PSI_UPS_NUT_LIST);
50
                    $upss = eval(PSI_UPS_NUT_LIST);
-
 
51
                } else {
-
 
52
                    $upss = array(PSI_UPS_NUT_LIST);
-
 
53
                }
46
            } else {
54
            } else {
47
                $upses = array(PSI_UPS_NUT_LIST);
55
               $upss = array('UPS');
-
 
56
            }
-
 
57
            $un = 0;
-
 
58
            foreach ($upss as $ups) {
-
 
59
                $temp = "";
-
 
60
                CommonFunctions::rftsdata("upsnut{$un}.tmp", $temp);
-
 
61
                if (! empty($temp)) {
-
 
62
                    $this->_output[$ups] = $temp;
-
 
63
                }
-
 
64
                $un++;
48
            }
65
            }
-
 
66
            break;
-
 
67
        default:
-
 
68
            if (defined('PSI_UPS_NUT_LIST') && is_string(PSI_UPS_NUT_LIST)) {
-
 
69
                if (preg_match(ARRAY_EXP, PSI_UPS_NUT_LIST)) {
-
 
70
                    $upses = eval(PSI_UPS_NUT_LIST);
-
 
71
                } else {
-
 
72
                    $upses = array(PSI_UPS_NUT_LIST);
-
 
73
                }
49
            foreach ($upses as $ups) {
74
                foreach ($upses as $ups) {
50
                CommonFunctions::executeProgram('upsc', '-l '.trim($ups), $output, PSI_DEBUG);
75
                    CommonFunctions::executeProgram('upsc', '-l '.trim($ups), $output, PSI_DEBUG);
-
 
76
                    $ups_names = preg_split("/\n/", $output, -1, PREG_SPLIT_NO_EMPTY);
-
 
77
                    foreach ($ups_names as $ups_name) {
-
 
78
                        $upsname = trim($ups_name).'@'.trim($ups);
-
 
79
                        $temp = "";
-
 
80
                        CommonFunctions::executeProgram('upsc', $upsname, $temp, PSI_DEBUG);
-
 
81
                        if (! empty($temp)) {
-
 
82
                            $this->_output[$upsname] = $temp;
-
 
83
                        }
-
 
84
                    }
-
 
85
                }
-
 
86
            } else { //use default if address and port not defined
-
 
87
                if (!defined('PSI_EMU_HOSTNAME')) {
-
 
88
                    CommonFunctions::executeProgram('upsc', '-l', $output, PSI_DEBUG);
-
 
89
                } else {
-
 
90
                    CommonFunctions::executeProgram('upsc', '-l '.PSI_EMU_HOSTNAME, $output, PSI_DEBUG);
-
 
91
                }
51
                $ups_names = preg_split("/\n/", $output, -1, PREG_SPLIT_NO_EMPTY);
92
                $ups_names = preg_split("/\n/", $output, -1, PREG_SPLIT_NO_EMPTY);
52
                foreach ($ups_names as $ups_name) {
93
                foreach ($ups_names as $ups_name) {
-
 
94
                    $temp = "";
53
                    CommonFunctions::executeProgram('upsc', trim($ups_name).'@'.trim($ups), $temp, PSI_DEBUG);
95
                    CommonFunctions::executeProgram('upsc', trim($ups_name), $temp, PSI_DEBUG);
54
                    if (! empty($temp)) {
96
                    if (! empty($temp)) {
55
                        $this->_output[trim($ups_name).'@'.trim($ups)] = $temp;
97
                        $this->_output[trim($ups_name)] = $temp;
56
                    }
98
                    }
57
                }
99
                }
58
            }
100
            }
59
        } else { //use default if address and port not defined
-
 
60
            if (!defined('PSI_EMU_HOSTNAME')) {
-
 
61
                CommonFunctions::executeProgram('upsc', '-l', $output, PSI_DEBUG);
-
 
62
            } else {
-
 
63
                CommonFunctions::executeProgram('upsc', '-l '.PSI_EMU_HOSTNAME, $output, PSI_DEBUG);
-
 
64
            }
-
 
65
            $ups_names = preg_split("/\n/", $output, -1, PREG_SPLIT_NO_EMPTY);
-
 
66
            foreach ($ups_names as $ups_name) {
-
 
67
                CommonFunctions::executeProgram('upsc', trim($ups_name), $temp, PSI_DEBUG);
-
 
68
                if (! empty($temp)) {
-
 
69
                    $this->_output[trim($ups_name)] = $temp;
-
 
70
                }
-
 
71
            }
-
 
72
        }
101
        }
73
    }
102
    }
74
 
103
 
75
    /**
104
    /**
76
     * parse the input and store data in resultset for xml generation
105
     * parse the input and store data in resultset for xml generation
Line 97... Line 126...
97
                    $dev->setMode($ups_data['driver.name']);
126
                    $dev->setMode($ups_data['driver.name']);
98
                }
127
                }
99
                if (isset($ups_data['ups.status'])) {
128
                if (isset($ups_data['ups.status'])) {
100
                    $dev->setStatus($ups_data['ups.status']);
129
                    $dev->setStatus($ups_data['ups.status']);
101
                }
130
                }
-
 
131
                if (isset($ups_data['ups.beeper.status'])) {
-
 
132
                    $dev->setBeeperStatus($ups_data['ups.beeper.status']);
-
 
133
                }
102
 
134
 
103
                //Line
135
                //Line
104
                if (isset($ups_data['input.voltage'])) {
136
                if (isset($ups_data['input.voltage'])) {
105
                    $dev->setLineVoltage($ups_data['input.voltage']);
137
                    $dev->setLineVoltage($ups_data['input.voltage']);
106
                }
138
                }
Line 135... Line 167...
135
    /**
167
    /**
136
     * get the information
168
     * get the information
137
     *
169
     *
138
     * @see PSI_Interface_UPS::build()
170
     * @see PSI_Interface_UPS::build()
139
     *
171
     *
140
     * @return Void
172
     * @return void
141
     */
173
     */
142
    public function build()
174
    public function build()
143
    {
175
    {
144
        $this->_info();
176
        $this->_info();
145
    }
177
    }