Apcupsd ネットワークモニタリング(CGI)プログラム

訳者:Que 21 Mar 2000 (http://homepage1.nifty.com/Que/)


コンフィグレーション

このリリースでは,4つのCGI プログラムmultimon.cgi, upsstats.cgi, upsfstats.cgi, and upsimage.cgi)がある。それらが正しくインストールされるために,--enable-cgi と共に ./configure を実行しなくてはならず,また --with-cgi-bin= と共にインストール先ディレクトリを指定しなくてはならないか,手動でそれらを移動しなくてはならない。CGI プログラムのデフォルトのインストール先ディレクトリは,/etc/apcupsd であり,そしてそれはこれらを使おうと思うなら本当に望ましい場所ではない。通常,これらは WEB サーバの cgi-bin に入らなくてはならない。

ひとたびビルトされロードされると,これらはネットワーク上にあなたの UPS あるいは UPS らの状態を与えるだろう。

通常,multimon.cgi だけがユーザによって直接呼び出される。しかしながら,upsstats.cgi および upsfstats.cgi を直接呼び出す事は,可能である。upsimage.cgi だけは,バーチャートを生成するために uspstats.cgi によって使われるので,決して直接呼び出してはならない。

CGI プログラムのセッティングとテスト

multimon およびその他の CGI プログラムを使う前に,最初に apcupsd がネットワークインフォメーションサーバを動かすために設定されていることを確認しなさい。これは,/etc/apcupsd/apcupsd.conf 内で NETSERVER をオンに設定する事でされます。追加の詳細情報は,このマニュアルのコンフィグレーションセクションのネットワークインフォメーションサーバセクションを見なさい。また,Client テストプログラムに関して,この章の終わりのセクションを見なさい。

次に,hosts ファイル "/etc/apcupds/hosts.conf" を編集し,末尾にモニタしたいホストの名前およびそれらのラベル文字列を付け加えなさい。私のサイトでは,配布ソースからの無修正の multicon.conf を使っており,以下の3行を含むように hosts.conf を修正した。

MONITOR matou "Server"
MONITOR polymatou "Backup server"
MONITOR deuter  "Disk server"
matou, polymatou, および deuter は,現在 apcupsd が動いている3台のマシンのネットワーク名である。

multimon.cgi をテストするため,cgi をビルドしたディレクトリから直接 root としてでなくこれを実行できる。そうするためには,シェルプロンプトで

./multimon.cgi

と入力する。

すべてが正しくセットアップされたなら,hosts.conf ファイルに追加したマシンのたくさんの値を含む HTML をプリントするだろう。そして,それは以下のように見えるだろう(注,ここで複写されているのは出力のほんの一部である)

Content-type: text/html

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN"
       "http://www.w3.org/TR/REC-html40/loose.dtd">
<HTML>
<HEAD><TITLE>Multimon: UPS Status Page</TITLE></HEAD>
<BODY BGCOLOR="#FFFFFF">
<TABLE BGCOLOR="#50A0A0" ALIGN=CENTER>
<TR><TD>
<TABLE CELLPADDING=5>
<TR>
<TH COLSPAN=10 BGCOLOR="#60B0B0">
<FONT SIZE="+2">APCUPSD UPS Network Monitor</FONT>
<BR>Sun Jan 16 12:07:27 CET 2000</TH>
</TR>
<TR BGCOLOR="#60B0B0">
<TH COLSPAN=1>System</TH>
<TH COLSPAN=1>Model</TH>
<TH COLSPAN=1>Status</TH>
...
もし似たような出力が得られないときは,WEB サーバがアクセスできるかどうかを確認するため,/etc/apcupsd ディレクトリのパーミッションや /etc/apcupsd/hosts.conf のそれをチェックしなさい。多くのサイト,たとえば私のも,では,Apache サーバは root としてでなく動作しているので,/etc/apcupsd/hosts.conf や /etc/apcupsd/multiomon.conf は世界から届くかどうか確認することに注意を払わなくてはならない。

貴方のブラウザから multimon を呼び出すために,以下を入力しなさい。

http://<your-site>/cgi-bin/multimon.cgi

以下に示すようなスクリーンショットに似た何かが得られるはずである。

これらのプログラムの動作例を見るには, http://www.sibbald.com/cgi-bin/multimon.cgi へ来なさい。

multimon.cgi

このプログラムは,複数の UPS を同時にモニタします。貴方の WEB ブラウザに表示される典型的な multimon.cgi の出力は,下記のように見えるだろう。

multimon.cgi

カラムヘッダや値と同様に,モニタされるマシンもすべて設定可能である(/etc/apcupsd/hosts.conf や /etc/apcupsd/multimon.conf を見なさい)。

upsstats.cgi

multimon.cgi ディスプレイにおいて System 名をクリックする事によって,指定されたシステムのための upsstats.cgi を呼び出せ,それはモニタされている値のうちの3つをバーチャートにする。たとえば,

upsstatus.cgi

3つのバーグラフのそれぞれの上部にあるドロップダウンメニューから異なる変数を選択する事により,異なるバーグラフを表示する事ができる。

multimon と同様,/etc/apcupsd/hosts.conf ファイル中でローカルホストを構成したなら,以下のようにして CGI ディレクトリで Unix シェルからそれを実行できる。

./upsstats.cgi

As with multimon, quite a few lines of html should then be displayed.

upsfstatus.cgi

If you would like to see all of the STATUS variables available over the network, click on the Data field of the desired system, and your browser will display something like the following:

APC      : 001,048,1109
DATE     : Thu Dec 02 17:27:21 CET 1999
HOSTNAME : matou.sibbald.com
RELEASE  : 3.7.0-beta-1
CABLE    : Custom Cable Smart
MODEL    : SMART-UPS 1000
UPSMODE  : Stand Alone
UPSNAME  : UPS_IDEN
LINEV    : 223.6 Volts
MAXLINEV : 224.9 Volts
MINLINEV : 222.3 Volts
LINEFREQ : 50.0 Hz
OUTPUTV  : 223.6 Volts
LOADPCT  :   6.2 Percent Load Capacity
BATTV    : 27.9 Volts
BCHARGE  : 100.0 Percent
MBATTCHG : 5 Percent
TIMELEFT : 167.0 Minutes
MINTIMEL : 3 Minutes
SENSE    : High
DWAKE    : 060 Seconds
DSHUTD   : 020 Seconds
LOTRANS  : 196.0 Volts
HITRANS  : 253.0 Volts
RETPCT   : 050.0 Percent
STATFLAG : 0x08 Status Flag
STATUS   : ONLINE
ITEMP    : 35.1 C Internal
ALARMDEL : Low Battery
LASTXFER : U command or Self Test
SELFTEST : NO
STESTI   : 336
DLOWBATT : 02 Minutes
DIPSW    : 0x00 Dip Switch
REG1     : 0x00 Register 1
REG2     : 0x00 Register 2
REG3     : 0x00 Register 3
MANDATE  : 01/11/99
SERIALNO : GS9903001147
BATTDATE : 01/11/99
NOMOUTV  : 230.0
NOMBATTV :  24.0
HUMIDITY : N/A
AMBTEMP  : N/A
EXTBATTS : 0
BADBATTS : N/A
FIRMWARE : 60.11.I
APCMODEL : IWI
END APC  : Thu Dec 02 17:27:25 CET 1999
You should get pretty much the same output mixed in with html if you execute upsfstats.cgi directly from a Unix shell in the cgi subdirectory as explained above for upsstats.cgi and multimon.cgi.

Working Example

To see a working example of the above programs, visit http://www.sibbald.com/cgi-bin/multimon.cgi.

Client Test Program

When your Network Information Server is up and running, you can test it using a simple program before attempting to access the server via you Web server. The test program is called client.c and can be found in the examples subdirectory of the source distribution. To build the program, when in the examples directory, use something like the following:

cc client.c ../apcnetlib.c -o client

Then execute it:

./client <host>

Where host is the name of the host or the IP address of the host running the Network Information Server. The default is the local host.

If no error messages are printed, it has most likely established contact with your server. Anything that you type as standard input will be passed to the server, and anything the server sends back will be printed to standard output. There are currently two commands recognized by the server: events and status. Hence the following commands:

./client
status
events
xyz
^D

Should produce the status listing (the same as produced by apcaccess status), followed by the list of the last 10 events (in response to the events command), and finally Invalid command in response to the xyz input, which is not a valid command. The control-D terminates the client program.

Credits

Many thanks go to Russell Kroll <rkroll@exploits.org> who wrote the CGI programs to work with his UPS Monitoring system named Network UPS Tools (NUT). Thanks also to Jonathan Benson <jbenson@technologist.com> for initially adapting the upsstatus.cgi program to work with apcupsd.

We have enhanced the bar graph program and hope that our changes can be useful to the original author in his project.