Cacti插件詳解——Weathermap

 

 

 

        這些漂亮的網絡拓撲都是用weathermap畫出來的!
這麼長時間了沒有發出來,今天就寫以下weathermap的用法,以下都是我自己的理解,如有錯誤之處請諒解!
weathermap是用來做網絡拓撲圖的,其中可以調用mrtg和cacti的流量圖,可以生成靜態的html頁面。具體的例子大家可以中國科大的這個http://linux.ustc.edu.cn/
weathermap的官方網站爲 http://www.network-weathermap.com/ weathermap有二種用法。第一種就是作爲cacti的插件使用,第二種就是獨立出來,可以獨立安裝一個weathermapm,當然要php,php-gd支持,weathermap最新版本爲weathermap-0.97a.
 

一.weathermap作爲cacti插件的用法

1.安裝weathermap插件


1
2
3
4
5
wget http://www.network-weathermap.com/files/php-weathermap-0.97a.zip
unzip php-weathermap-0.97a.zip
mv weathermap/ /var/www/html/plugins/
chown -R apache:apache /var/www/html/plugins/weathermap/configs/
chown -R apache:apache /var/www/html/plugins/weathermap/output/
下面我們打開cacti,點console——Plugin Management,就可以看到weathermap了,點前面那個點就可以安裝weathermap

 

 

點擊安裝weathermap後

至此,weathermap已經安裝成功。

2.配置使用weathermap

安裝好weathermap後,看到點Console在左邊的列表裏會看到weathermap的菜單,我們點擊,會看到設置,因爲我們還沒有定義一個weathermap配置文件,所以我們點右上角的Add按鈕,添加一個weathermap配置文件

點擊Add之後,我們看到有二個文件,其實這個時候調用的就是weathermap的configs目錄下的文件,simple.conf就是自帶的一個配置文件,我們可以點擊它前面的Add按鈕,把他添加到默認配置文件裏

至此我們添加了一個weathermap的配置文件,下面就是對weathermap進行配置了,點擊weathermap,然後點擊Editor對默認圖形配置文件進行配置。

點擊editor後我們會看到如下提示

 

The editor has not been enabled yet. You need to set ENABLED=true at the top of editor.php

Before you do that, you should consider using FilesMatch (in Apache) or similar to limit who can access the editor. There is more information in the install guide section of the manual.

 

我們按照他提示的編輯editor.php


1
vi /var/www/html/plugins/weathermap/editor.php

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
<php 
 
require_once 'editor.inc.php';
require_once 'Weathermap.class.php';
 
// so that you can't have the editor active, and not know about it.
$ENABLED=true;
 
if(! $ENABLED)
{
print "   The editor has not been enabled yet. You need to set ENABLED=true at the top of editor.php   ";
print "   Before you do that, you should consider using FilesMatch (in Apache) or similar to limit who can access the editor. There is more information in the install guide section of the manual.   ";
exit();
}
把上面的$ENABLED=false;改爲$ENABLED=true;然後保存。之後我們刷新頁面就可以看到如下頁面

 

在這裏我們可以創建配置文件,或者從一個配置文件創建一個新的配置文件,或者打開一個已有的配置文件進行編輯,這裏我們就點擊simple.conf文件做一個簡單的weathermap配置。點擊simple.conf可以看到下圖
 
這裏就是weathermap的編輯頁面了,把上面那個幾次菜單翻譯下吧。
Change File可以會到前面的那個界面改變編輯的圖形配置文件。
Add Node就是添加一個節點,點擊之後鼠標會變成變成一個十字,在你想要放Node的地方點一下就可以創建一個Node。
Add Link 就是添加添加一條鏈接,可以把二個Node連接起來,點擊Add Link後點擊Node,再點擊另外一個Node就可以把二個Node連接起來。
Position Legend是調整那個圖列的位置,點擊之後鼠標會編成十字,點擊以下就可以移動到新的位置。
Postion Timestamp就是添加一個圖片創建的時間啊什麼信息的。
Map Style 可以調整這個圖形的風格。比如圖形名稱、.圖形大小、圖形背景圖片、輸出圖片目錄、位置等
基本使用的也就這幾個了。點擊一個Node
 
這裏可以改Node的大小,Node的名稱和標籤名稱,Info URl是用戶把鼠標放在這個Node後會出現一個流量圖片,這個圖片信息來自那裏,Hover Graph URL 這裏是當用戶點擊這個Node是會跳轉到那個圖,在這裏可以選擇點擊Pick From Cacti,從cacti中選取,Icon Filename是圖標的圖像,這裏可以有很多比如Router、Host、firewall。當然也可以自己添加,在weathermap的images裏,設置好有點擊Submit就可以提交更改了.
我們在設置以下Link,點擊Link的那條線
 
 
 
Maximum Bandwidth Into這裏是設置這條Link的最大帶寬,這裏根據你自己的具體配置設置了,這裏端口是1G的端口,出口帶寬是300MB因此我設置爲300MB,Maximum Bandwidth out 是出去的最大流量帶寬,可以根據自己的具體情況設置。Data source是流量從那裏獲取,這裏可以引用mrtg的流量也可以點擊Pick form Cacti從cacti裏獲取,Info URl是用戶把鼠標放在這個Node後會出現一個流量圖片,這個圖片信息來自那裏,Hover Graph URL 這裏是當用戶點擊這個Node是會跳轉到那個圖,這個如果選擇從cacti獲取會自動取得。從mrtg要自己設置下。別的默認就成。這樣我們就我完成了對一張拓撲圖的編輯。如下就是我設計的weathermap圖像
 
 

注意問題

1,中文顯示,我們可以在配置文件裏指定中中文字體的路徑

1
2
vi /var/www/html/plugins/weathermap/configs/simple.conf
FONTDEFINE 100 /var/www/html/plugins/weathermap/msyh.ttf 10
msyh.ttf是中文字體的名字.需要用戶自己加進去,指定路徑,後面10字體是大小
2.每次對圖形進行調整後,都是自動保存的,不用保存(也沒有那個選項!嘿嘿),要在weathermap裏看到修改後的效果要等到下次cacti採集器採集後纔會繪圖。
<>
>3.cacti的日誌裏可能會顯示
 
WEATHERMAP: Poller[0] [Map 1] simple.conf: About to write image file. If this is the last message in your log, increase memory_limit in php.ini [WMPOLL01]
等信息,不過我修改php.ini裏的設置也不起作用,不用管它!
4.可以在cacti的裏進行設置,如圖,一般默認就成
 

二.weathermap獨立的使用。

通過在catci裏的設置,大家會weathermap已經有了一個認識了,其實它就是用過一個配置文件,繪圖,引用cacti或者mrtg的流量和圖形就成了
 

1.安裝基本環境


1
2
3
4
5
6
7
8
9
yum install httpd php php-gd  php-pear rrdtool -y
servie http start
chkconfig http on
service crond start
chkconfig crond on
wget http://www.network-weathermap.com/files/php-weathermap-0.97a.zip
unzip php-weathermap-0.97a.zip
mv weathermap/ /var/www/html/
chown -R apache:apache /var/www/html/weathermap/configs/

2.配置weathermap

 

我們要配置我們的圖形配置文件
 
先編輯editor.php

1
vi /var/www/html/weathermap/editor.php
把裏面的$ENABLED=false;改爲$ENABLED=true;$ignore_cacti=False;改爲$ignore_cacti=True;然後保存。
之後我們打開http://xxx.xxx.xxx.xxx/weathermap/editor.php
就可以像在cacti裏一樣設計自己的weathermap圖形了,

 

特別注意:

 

1.在這裏ICO的路徑要選擇絕對路徑,不讓路徑會有錯誤,導致不能出圖。
2.eidtor.php裏可以設置拓撲圖輸出的路徑Image的路徑直接寫名稱,不用寫路徑,Html的路徑路徑要寫絕對路徑。
3.在weathermap目錄裏有個weathermap文件要設置rrdtools的路徑。$rrdtool=”/usr/bin/rrdtool”;
關於配置文件的我們可以weathermap官網找到
weathermap官網的設置:http://www.network-weathermap.com/manual/latest/pages/config-reference.html 具體的參數這裏都有
這裏還有一個配置文件的範本http://www.network-weathermap.com/manual/latest/pages/main.html#example
這個是做好的圖形;http://www.network-weathermap.com/manual/latest/example/example.html

 

3.生成圖形

 

設置好圖形配置文件後我們就要生成圖形了,在cacti裏這個是通過cacti的採集器實現的,在單獨安裝weathermap的後,需要利用系統的計劃任務來實現
我們先執行一次

1
/usr/bin/php /var/www/html/weathermap/weathermap --config /var/www/html/weathermap/configs/simple.conf --image-uri ../weathermap/test.png
就可以在/下生成一個test.png圖片,然後我們編輯

1
vi /etc/crontab
添加如下

1
*/5 * * * * root /usr/bin/php /var/www/html/weathermap/weathermap --config /var/www/html/weathermap/configs/simple.conf --image-uri ../weathermap/test.png
然後我們要做個硬鏈接不讓png圖片的路徑會有錯誤

1
ln /test.png /var/www/html/weathermap/test.png
至此我們的weathermap已經做好我們可以打開http://xxx.xxx.xxx.xxx/weathermap/index.html查看拓撲圖。
我最終的拓撲圖

 

總結:

 

1.weathermap的用法就說到這裏,基本就是這二種了,還有的是自己做一個html,再嵌套一個weathermap的頁面就像剛開始給大家說的那個中國科大的,就是通過網頁的嵌套做到的,嵌套了mrtg,weathermap的頁面。
2.在單獨使用weathermap時要特別注意路徑問題,不出圖形很有可能是路徑問題,這個問題我也糾結了很久。

3.最重要的一點,就是關於weathermap的安全性問題,其實在它的官網也說明了。

地址:http://www.network-weathermap.com/manual/latest/pages/install-cacti-editor.html

 

When you are happy that the world can’t edit your maps, then enable the editor. This is done by editing the top of editor.php and changing $ENABLED=false; to $ENABLED=true;

You should now be able to go to http://your.server/cacti/plugins/weathermap/editor.php in a browser, and get a welcome page that offers to load or create a config file. That’s it. All done. Please see the editor manual page for more about using the editor!

You can also edit an existing map from the Cacti web interface, by choosing Manage..Weathermaps and then clicking on the name of a config file in the list of active maps. The editor will open with that map loaded.

Important Security Note: The editor allows anyone who can access editor.php to change the configuration files for your network weathermaps. There is no authentication built-in for editing, even with the Cacti Plugin. This is why the configuration file doesn’t exist by default – the editor won’t work until you choose to make it work. It’s recommended that you either:

  • change the ownership of configuration files so that the editor can’t write to them once they are complete, or
  • use your webserver’s authentication and access control facilities to limit who can access the editor.php URL. On apache, this can be done using the FilesMatch directive and mod_access.
可以看到在默認情況下editor.php這個是沒有做驗證的,就是意味每個人都可以編輯你的weathermap圖形配置文件!!!!發現很多使用weathermap都沒做限制,有些還是直接到公網的,再次特別提醒,一定要做一個驗證!
下面我提供一種方法。
修改httpd.conf配置文件

1
vi /etc/httpd/conf/httpd.conf
在文件最後添加

1
2
3
4
5
6
7
<Directory /var/www/html/weathermap>
   <Files editor.php>
            Order Deny,Allow
            Deny from all
            Allow from 127.0.0.1
        </Files>
</Directory>
 然後保存,這個路勁是weathermap的路徑.這樣就可以限制別人訪問editor.php的訪問.設置好後重啓apache,再訪問那個頁面就會出現這個頁面
當然也可以做一個基於.htaccess的驗證。
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章