拜读刘天斯的一个开源项目
這兩天在測試劉天斯寫的一個開源工具-服務器機柜模擬圖,以下是我想額外實現的功能,僅提供參考,也許某些人和我有一樣的想法,所以今天把我這兩天修改的一些地方提出來。
?
在這里我想要實現以下功能:
(1)???? 解決一個機柜多與10臺服務器(默認10,現在14)
(2)???? 增加機柜數(默認7,現在8)
(3)???? 增加描述關鍵字
(4)???? 增加交換機圖
(5)???? 當機展示
所有問題解決都是在servermap.cpp代碼中修改
第1個問題,解決方法(在此方法: void servermap::ProduRow()內)
for (int k=1;k<=14;k++)
??????????????????????? {
??????????????????????????????? if (k>=10)
??????????????????????????????????????? point_last="-"+int2str(k);
紅色字體是修改部分,原先代碼如下,這樣我們就一個機柜就可以有14臺服務器了
for (int k=1;k<=10;k++)
??????????????????????? {
??????????????????????????????? if (k==10)
?? ?????????????????????????????????????point_last="-10";
這里需要注意下,這樣會將背景拉長,所以我們需要將jg.gif這張背景圖增長,通過photoshop拉長,我增加4臺服務器,所以我增長了280元素,現為720元素,并且還要修改HTMLstr+="<table width='99%' height='720'? border='0' cellpadding='1' cellspacing='0'>\n";
第2個問題,解決比較簡單(在此方法: void servermap::ProduRow()內)
for (int j=1;j<=8;j++)
?????????????? ?{
??????????????????????? point_moddle=point_moddle_key+int2str(j);
??????????????????????? HTMLstr+="<td width='147' bgcolor='#eeeeee' background=\"/images/serverico/jg.gif\" >\n";
紅色字體是修改部分,原先代碼如下,這樣我們一排就有8個機柜了
for (int j=1;j<=7;j++)
??????????????? {
??????????????????????? point_moddle=point_moddle_key+int2str(j);
??????????????????????? HTMLstr+="<td width='147' bgcolor='#eeeeee' background=\"/images/serverico/jg.gif\" >\n";
?
第3個問題,解決方法
??????????????? string idctype;
??????????????? string (*p_info)[6];??? // 所有的服務器信息指針(從XML文件中遍歷);
??????????????? string (*pserver_info)[6];????? // 當前機房的服務器信息指針(從XML文件中遍歷);
??????????????? string ServerInfo[800][6];????? // 所有的服務器信息數組(從XML文件中遍歷);
??????????????? string ServerInfo_CurrServer[300][6];?? //當前機房數組,從ServerInfo中過濾出來;
?
原先是5,這里因為要增加一行,所以修改為6
?
在void servermap::ProduCurrServer()方法內添加
??????????????????????????????? CurrServerInfoNumber+=1;
??????????????????????????????? ServerInfo_CurrServer[CurrServerInfoNumber][0]=*(*(p_info+j)+0);
??????????????????????????????? ServerInfo_CurrServer[CurrServerInfoNumber][1]=*(*(p_info+j)+1);
??????????????????????????????? ServerInfo_CurrServer[CurrServerInfoNumber][2]=*(*(p_info+j)+2);
??????????????????????????????? ServerInfo_CurrServer[CurrServerInfoNumber][3]=*(*(p_info+j)+3);
??????????????????????????????? ServerInfo_CurrServer[CurrServerInfoNumber][4]=*(*(p_info+j)+4);
??????????????????????????????? ServerInfo_CurrServer[CurrServerInfoNumber][5]=*(*(p_info+j)+5);
再在void servermap::ProduRow()函數添加
??? ????????????????????????????????????if (point_all==substrServer)
??????????????????????????????????????? {
??????????????????????????????????????????????? DIVstr+="IP:"+*(*(pserver_info+m)+0)+"<br>";
???????????????????????????????????????? ???????DIVstr+="操作系統:"+*(*(pserver_info+m)+2)+"<br>";
??????????????????????????????????????????????? DIVstr+="位置:"+*(*(pserver_info+m)+3)+"<br>";
??????????????????????????????????????????????? DIVstr+="機型:"+*(*(pserver_info+m)+4)+"<br>";
??????????????? ????????????????????????????????DIVstr+="描述型:"+*(*(pserver_info+m)+5)+"<br>";
?
當然,你還需要在ServerInfoAll.xml添加一行
<serverinfo>
<ip>192.168.2.1</ip>
<classid>40</classid>
<os>Centos5.5</os>
<locate>01-01-02</locate>
<bodytype>1U</bodytype>
<description>This is server!</description>
</serverinfo>
這樣就滿足了我人的需求了
?
第4個問題,和前面一個差不多,只不過需要增加一個方法,做些交換機up,down的gif.
第1步,先做switch up,down動畫,此步略
第2步, 再在ServerInfoAll.xml添加一行,如下:
<serverinfo>
<ip>192.168.1.1</ip>
<classid>40</classid>
<os>H3C</os>
<locate>01-01-01</locate>
<bodytype>2U</bodytype>
<type>switch</type>
<description>This is switch-H3c!</description>
</serverinfo>
第3步,如上面增加一個關鍵字“描述”做法一樣,按前面的做法,再做一次.
第4步,再加一個判定條件和一個交換機狀態函數,函數名GetSwitchCondition
條件判斷,如下
??????????????????????????????????????????????? if(*(*(pserver_info+m)+5)=="server")
??????????????????????????????????????????????????? if (*(*(pserver_info+m)+4)=="1U")
??????????????????????????????????????????????????????? HTMLstr+="<img src='/images/serverico/"+GetServerCondition(*(*(pserver_info+m)+0),"1U")+"' width='127' height='12' style=\"vertical-ali
gn:bottom;\" ?return false\" ?return false\">";
??????????????????????????????????????????????????? else if (*(*(pserver_info+m)+4)=="2U")
??????????????????????????????????????????????????????? HTMLstr+="<img src='/images/serverico/"+GetServerCondition(*(*(pserver_info+m)+0),"2U")+"' width='127' height='24' style=\"vertical-ali
gn:bottom;\" ?return false\" ?return false\">";
??????????????????????????????????????????????????? else??????? HTMLstr+="<img src='/images/serverico/"+GetServerCondition(*(*(pserver_info+m)+0),"6U")+"'? height='76' style=\"vertical-align:
bottom;\" ?return false\" ?return false\">";
??????????????????????????????????????????????? else?? HTMLstr+="<img src='/images/serverico/"+GetSwitchCondition(*(*(pserver_info+m)+0),"1U")+"' width='127' height='12' style=\"vertical-alig
n:bottom;\" ?return false\" ?return false\">";
?
string servermap::GetSwitchCondition (string ip,string servertype)
{
?
??????? bool Obtaining=false;
??????? for (int i=0;i<50;i++)
??????? {
??????????????? if (ServerDownIP[i].c_str()==ip)
????? ??????????{
??????????????????????? Obtaining=true;
??????????????????????? break;
??????????????? }
??????? }
??????? //printf("%s",ip.c_str());
??????? if (servertype=="1U")
??????? if (Obtaining)
??????????????? return "switch_down.gif";
??????? else return "switch_up.gif";
}
其實,這里不需要傳遞交換機的size的,但我想以后交換機有大與1U的,那到時候還需要再寫,索性就保留吧。
第5個問題,這個問題比較簡單,不知道是不是劉天斯故意這樣做的,沒有將獲取主機Down信息的函數放到合適的位置,導致此功能無法實現。
解決方法:在構造函數中,將???????
//獲取當前服務器清單;
??????? Getdownserver();
此函數調用放到???????
//當機文件位置初始化;
??????? downfile="/home/ServerMap/ServerDownlist";
這個下面就成了,因為Getdownserver()函數需要讀取此變量!
?
OK,搞定!可能還有些大門呀,qiang什么之類的,估計需要修改css/js這些了,那需要微調到,等真需要,再搞吧!
貼些圖:
ServerInfoAll.xml
<?xml version="1.0" ?><wml>
<serverinfo>
<ip>192.168.1.1</ip>
<classid>40</classid>
<os>H3C</os>
<locate>01-01-01</locate>
<bodytype>2U</bodytype>
<type>switch</type>
<description>This is switch-H3c!</description>
</serverinfo>
<serverinfo>
<ip>192.168.2.1</ip>
<classid>40</classid>
<os>Centos5.5</os>
<locate>01-01-02</locate>
<bodytype>1U</bodytype>
<type>server</type>
<description>This is server!</description>
</serverinfo>
<serverinfo>
<ip>192.168.2.2</ip>
<classid>40</classid>
<os>Centos5.5</os>
<locate>01-01-03</locate>
<bodytype>1U</bodytype>
<type>server</type>
<description>This is server!</description>
</serverinfo>
......
在這里還是再感謝劉天斯大俠,多出精文噢!好讓我們多多學習!
如果想了解更多,請關注我們的公眾號
公眾號ID:opdevos
掃碼關注
?
轉載于:https://blog.51cto.com/5ydycm/1131289
總結
以上是生活随笔為你收集整理的拜读刘天斯的一个开源项目的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: svn绿色符号消失的解决办法
- 下一篇: mybatis表不存在的解决办法