Subversion Repositories ALCASAR

Rev

Rev 2775 | Rev 3037 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log

Rev Author Line No. Line
2775 rexy 1
<?php
2
/**
3
 * Apcupsd class
4
 *
5
 * PHP version 5
6
 *
7
 * @category  PHP
8
 * @package   PSI_UPS
9
 * @author    Michael Cramer <BigMichi1@users.sourceforge.net>
10
 * @copyright 2009 phpSysInfo
11
 * @license   http://opensource.org/licenses/gpl-2.0.php GNU General Public License version 2, or (at your option) any later version
12
 * @version   SVN: $Id: class.apcupsd.inc.php 661 2012-08-27 11:26:39Z namiltd $
13
 * @link      http://phpsysinfo.sourceforge.net
14
 */
15
 /**
16
 * getting ups information from apcupsd program
17
 *
18
 * @category  PHP
19
 * @package   PSI_UPS
20
 * @author    Michael Cramer <BigMichi1@users.sourceforge.net>
21
 * @author    Artem Volk <artvolk@mail.ru>
22
 * @copyright 2009 phpSysInfo
23
 * @license   http://opensource.org/licenses/gpl-2.0.php GNU General Public License version 2, or (at your option) any later version
24
 * @version   Release: 3.0
25
 * @link      http://phpsysinfo.sourceforge.net
26
 */
27
class Apcupsd extends UPS
28
{
29
    /**
30
     * internal storage for all gathered data
31
     *
32
     * @var array
33
     */
34
    private $_output = array();
35
 
36
    /**
37
     * get all information from all configured ups in phpsysinfo.ini and store output in internal array
38
     */
39
    public function __construct()
40
    {
41
        parent::__construct();
42
        if (defined('PSI_UPS_APCUPSD_LIST') && is_string(PSI_UPS_APCUPSD_LIST)) {
43
            if (preg_match(ARRAY_EXP, PSI_UPS_APCUPSD_LIST)) {
44
                $upses = eval(PSI_UPS_APCUPSD_LIST);
45
            } else {
46
                $upses = array(PSI_UPS_APCUPSD_LIST);
47
            }
48
            foreach ($upses as $ups) {
49
                CommonFunctions::executeProgram('apcaccess', 'status '.trim($ups), $temp);
50
                if (! empty($temp)) {
51
                    $this->_output[] = $temp;
52
                }
53
            }
54
        } else { //use default if address and port not defined
2976 rexy 55
            if (!defined('PSI_EMU_HOSTNAME')) {
56
                CommonFunctions::executeProgram('apcaccess', 'status', $temp);
57
            } else {
58
                CommonFunctions::executeProgram('apcaccess', 'status '.PSI_EMU_HOSTNAME, $temp);
59
            }
2775 rexy 60
            if (! empty($temp)) {
61
                $this->_output[] = $temp;
62
            }
63
        }
64
    }
65
 
66
    /**
67
     * parse the input and store data in resultset for xml generation
68
     *
69
     * @return Void
70
     */
71
    private function _info()
72
    {
73
        foreach ($this->_output as $ups) {
74
 
75
            $dev = new UPSDevice();
76
 
77
            // General info
78
            if (preg_match('/^UPSNAME\s*:\s*(.*)$/m', $ups, $data)) {
79
                $dev->setName(trim($data[1]));
80
            }
81
            if (preg_match('/^MODEL\s*:\s*(.*)$/m', $ups, $data)) {
82
                $model = trim($data[1]);
83
                if (preg_match('/^APCMODEL\s*:\s*(.*)$/m', $ups, $data)) {
84
                    $dev->setModel($model.' ('.trim($data[1]).')');
85
                } else {
86
                    $dev->setModel($model);
87
                }
88
            }
89
            if (preg_match('/^UPSMODE\s*:\s*(.*)$/m', $ups, $data)) {
90
                $dev->setMode(trim($data[1]));
91
            }
92
            if (preg_match('/^STARTTIME\s*:\s*(.*)$/m', $ups, $data)) {
93
                $dev->setStartTime(trim($data[1]));
94
            }
95
            if (preg_match('/^STATUS\s*:\s*(.*)$/m', $ups, $data)) {
96
                $dev->setStatus(trim($data[1]));
97
            }
98
            if (preg_match('/^ITEMP\s*:\s*(.*)$/m', $ups, $data)) {
99
                $temperatur = trim($data[1]);
100
                if (($temperatur !== "-273.1 C") && ($temperatur !== "-273.1 C Internal")) {
101
                    $dev->setTemperatur($temperatur);
102
                }
103
            }
104
            // Outages
105
            if (preg_match('/^NUMXFERS\s*:\s*(.*)$/m', $ups, $data)) {
106
                $dev->setOutages(trim($data[1]));
107
            }
108
            if (preg_match('/^LASTXFER\s*:\s*(.*)$/m', $ups, $data)) {
109
                $dev->setLastOutage(trim($data[1]));
110
            }
111
            if (preg_match('/^XOFFBATT\s*:\s*(.*)$/m', $ups, $data)) {
112
                $dev->setLastOutageFinish(trim($data[1]));
113
            }
114
            // Line
115
            if (preg_match('/^LINEV\s*:\s*(\d*\.\d*)(.*)$/m', $ups, $data)) {
116
                $dev->setLineVoltage(trim($data[1]));
117
            }
118
            if (preg_match('/^LINEFREQ\s*:\s*(\d*\.\d*)(.*)$/m', $ups, $data)) {
119
                $dev->setLineFrequency(trim($data[1]));
120
            }
121
            if (preg_match('/^LOADPCT\s*:\s*(\d*\.\d*)(.*)$/m', $ups, $data)) {
122
                $dev->setLoad(trim($data[1]));
123
            }
124
            // Battery
125
            if (preg_match('/^BATTDATE\s*:\s*(.*)$/m', $ups, $data)) {
126
                $dev->setBatteryDate(trim($data[1]));
127
            }
128
            if (preg_match('/^BATTV\s*:\s*(\d*\.\d*)(.*)$/m', $ups, $data)) {
129
                $dev->setBatteryVoltage(trim($data[1]));
130
            }
131
            if (preg_match('/^BCHARGE\s*:\s*(\d*\.\d*)(.*)$/m', $ups, $data)) {
132
                $dev->setBatterCharge(trim($data[1]));
133
            }
134
            if (preg_match('/^TIMELEFT\s*:\s*(\d*\.\d*)(.*)$/m', $ups, $data)) {
135
                $dev->setTimeLeft(trim($data[1]));
136
            }
137
            $this->upsinfo->setUpsDevices($dev);
138
        }
139
    }
140
 
141
    /**
142
     * get the information
143
     *
144
     * @see PSI_Interface_UPS::build()
145
     *
146
     * @return Void
147
     */
148
    public function build()
149
    {
150
        $this->_info();
151
    }
152
}