操作系統(tǒng)日志配置方法_第1頁
操作系統(tǒng)日志配置方法_第2頁
操作系統(tǒng)日志配置方法_第3頁
操作系統(tǒng)日志配置方法_第4頁
操作系統(tǒng)日志配置方法_第5頁
已閱讀5頁,還剩14頁未讀, 繼續(xù)免費(fèi)閱讀

付費(fèi)下載

下載本文檔

版權(quán)說明:本文檔由用戶提供并上傳,收益歸屬內(nèi)容提供方,若內(nèi)容存在侵權(quán),請進(jìn)行舉報(bào)或認(rèn)領(lǐng)

文檔簡介

操作系統(tǒng)日志配置方法AIX、Linux和Solaris

操作系統(tǒng)日志接入

1.采用Root帳號登陸目標(biāo)系統(tǒng)

2.查看/etc/syslog.conf文件已經(jīng)成功添加以下內(nèi)容

*.err@采集機(jī)IP地址(中間以Tab健分割)@采集機(jī)IP地址

(中間以Tab健分割).用下面的命令停止syslog服務(wù)/etc/init.d/syslog

stop

3.用下面的命令啟動syslog服務(wù)/etc/init.d/syslogstartHPUNIX

1.在Unix系統(tǒng)/etc/syslog.conf文件最后追加以下2行*.err@采集機(jī)IP地址

(中間以Tab健分割)

@采集機(jī)IP地址(中間以Tab健分割).用下面的命令停止

syslog服務(wù)

Kill-9syslogd.用下面的命令啟動syslog服務(wù)

/usr/sbin/syslogdWindOWS操作系統(tǒng)日志接入

Windows操作系統(tǒng)需要安裝日志采集程序。安裝完成以后進(jìn)行如下配置:

修改配置文件:SEMCollectCfg.xml,默認(rèn)安裝時(shí)位于C:\PrograrrFiles\iS-

One\SEMCollector\conf目錄下。

修改一下紅色標(biāo)記內(nèi)容:

〈SYSTEM)調(diào)用xmlFreeNode或者xmlFreeNodeList來釋放動態(tài)分

配的節(jié)點(diǎn)內(nèi)存,除非你把該節(jié)點(diǎn)從文檔中移除了。一般來說,一個(gè)文

檔中所有節(jié)點(diǎn)都應(yīng)該動態(tài)分配,然后加入文檔,最后調(diào)用

xmlFreeDoc一次釋放所有節(jié)點(diǎn)申請的動態(tài)內(nèi)存,這也是為什么我們

很少看見xmlNodeFree的原因。

xmlSaveFile將文檔以默認(rèn)方式存入一個(gè)文件。

xmlSaveFormatFileEnc可將文檔以某種編碼/格式存入一個(gè)文件

中。

5)節(jié)點(diǎn)類型xmlNode.指針xmlNodePtr

節(jié)點(diǎn)應(yīng)該是xml中最重要的元素了,xmlNode代表了xml文檔

中的一個(gè)節(jié)點(diǎn),實(shí)現(xiàn)為一個(gè)struct,內(nèi)容很豐富:tree.h

typedefstruct_xmlNodexmlNode;

typedefxmlNode*xmlNodePtr;

struct_xmlNode{void*_private;/*applicationdata*/

xmlElementTypetype;/*typenumber,mustbesecond!

*/

constxmlChar*name;/*thenameofthenode,orthe

entity*/struct_xmlNode*children;/*parent->childslink*/

struct_xmlNode*last;/*lastchildlink*/struct_xmlNode

"parent;/*child->parentlink*/

struct_xmlNode*next;/*nextsiblinglink*/

struct_xmlNode*prev;/*previoussiblinglink*/struct

_xmlDoc*doc;/*thecontainingdocument*//*Endof

commonpart*/

xmlNs*ns;/*pointertotheassociatednamespace

*/xmlChar"content;/*thecontent*/

struct_xmlAttr"properties;/*propertieslist*/

xmlNs*nsDef;/*namespacedefinitionsonthisnode

*/void*psvi;/*fortype/PSVIinformations*/

unsignedshortline;/*linenumber*/

unsignedshortextra;/*extradataforXPath/XSLT*/

};

可以看到,節(jié)點(diǎn)之間是以鏈表和樹兩種方式同時(shí)組織起來的,next

和prev指針可以組成鏈表,而parent和children可以組織為樹。同

時(shí)還有以下重要元素:

?節(jié)點(diǎn)中的文字內(nèi)容:content;

?節(jié)點(diǎn)所屬文檔:doc;

?節(jié)點(diǎn)名字:name;

節(jié)點(diǎn)的namespace:ns;

xmlNodePtr*nodeTab;/*arrayofnodesinnoparticular

order*/

/*@@with_nstocheckwethernamespacenodesshould

belookedat@@*/

);

可以看出,節(jié)點(diǎn)集合有三個(gè)成員,分別是節(jié)點(diǎn)集合的節(jié)點(diǎn)數(shù)、最大

可容納的節(jié)點(diǎn)數(shù),以及節(jié)點(diǎn)數(shù)組頭指針。對節(jié)點(diǎn)集合中各個(gè)節(jié)點(diǎn)的訪問

方式很簡單,如下:

xmlNodeSetPtrnodeset=XPATH查詢結(jié)果;

for(inti=0;i<nodeset->nodeNr;i++)

{nodeset->nodeTab[i];

)

注意,Iibxml2是一個(gè)c函數(shù)庫,因此其函數(shù)和數(shù)據(jù)類型都使用c

語言的方式來處理。如果是C++,我想我寧愿用STL中的vector來表

示一個(gè)節(jié)點(diǎn)集合更好,而且沒有內(nèi)存泄漏或者溢出的擔(dān)憂。

五、使用Libxml2

工程中要實(shí)現(xiàn)一個(gè)管理XML文件的后臺程序,需要對XML文件進(jìn)行創(chuàng)

立,解析,修改,查找等操作,下面介紹如何利用libxml2提供的庫來

實(shí)現(xiàn)上述功能。

1、創(chuàng)立XML文檔:

我們使用xmlNewDocO來創(chuàng)立XML文檔,然后使用xmlNewNode(),

xmlNewChild(),xmlNewProp(),xmlNewText()等函數(shù)向XML文件中添

加節(jié)點(diǎn)及子節(jié)點(diǎn),設(shè)置元素和屬性,創(chuàng)立完畢后用

xmlSaveFormatFileEnc()來保存XML文件到磁盤(該函數(shù)可以設(shè)置保存

XML文件時(shí)的編碼格式)。

例如L

#include<stdio.h>

ttinclude<libxml/parser.h>

ttinclude<libxml/tree.h>

intmain(intargc,char**argv)xmlDocPtrdoc=NULL;

documentpointerVxmlNodePtrroot,node=NULL,node=NULL,

nodel=NULL;/*nodepointers*///Createsanewdocument,anode

andsetitasarootnode

doc=xmlNewDoc(BADCASTz,L0/z);root_rode

xmlNewNode(NULL,BADCAST

xmlDocSetRootElement(doc,root_node);

//createsanewnode,whichis"attached”as

childnodeofroot_nodenode.

xmlNewChild(rootnode,NULL,BADCASTZ,node?

z,BADCAST11contentofnodel〃);

//xmlNewProp()createsattributes,whichis

“attached"toannode.

node=xmlNewChiId(rootnode,NULL,BADCAST〃

r.ode3〃,BADCAST,fnodehasattributes");

xmlNewProp(node,BADCAST〃attribute”,

BADCASTlfyes11);//Heregoesanotherwaytocreatenodes.

node=xmlNewNode(NULL,BADCAST〃node4〃);

nodel=xmlNewText(BADCASTotherwayto

createcontent");xmlAddChiId(node,nodel);

xmlAddChild(rootnode,node);//Dumping

documenttosldioorfile

xm1SaveFormatFi1eEnc(argc>1?argv[l]:

"一〃,doc,〃UTF-8",1);/*freethedocument*/

xmlFreeDoc(doc);xmlCleanupParser();

xmlMemoryDumpO;//debugmemoryforregression

tests

return(0);

}編譯:

gcc-oxmlCreatorxmlCreator.cpp-I

/home/usr/libxml2/xmlinst/include/libxml2/

-L/home/usr/libxml2/xmlinst/lib/-Ixml2(綠色文字為

Iibxml2安凄艇在卜[后接頭文件目錄-L后接lib庫目錄

2、解析XML文檔

解析文檔時(shí)僅僅需要文件名并只調(diào)用一個(gè)函數(shù),并有錯誤檢查,常用

的相關(guān)函數(shù)有xmlParseFile(),xmlParseDoc(),獲取文檔指針后,就

可以使用xmlDocGetRootElement()來獲取根元素節(jié)點(diǎn)指針,利用該指針

就可以在D0M樹里漫游了,結(jié)束后要調(diào)用xmlFreeDocO釋放。

例如2:

xmlDocPtrdoc;〃定義解析文檔指針

xmlNodePtrcur;〃定義結(jié)點(diǎn)指針(你需要它為了在各個(gè)結(jié)點(diǎn)間移動)

xmlChar*key;

doc=xmlReadFile(url,MY_ENCODING,256);〃解析文件

/*檢查解析文檔是否成功,如果不成功,libxml將指一個(gè)注冊的錯

誤并停止。一個(gè)常見錯誤是不適當(dāng)?shù)木幋a。XML標(biāo)準(zhǔn)文檔除了用UTF-8或

ITFT6外還可用其它編碼保存。如果文檔是這樣,libxml將自動地為你

轉(zhuǎn)換到UTF-8。更多關(guān)于XML編碼信息包含在XML標(biāo)準(zhǔn)中。*/

if(doc==NULL){fprintf(stderr,Documentnotparsed

successfully.\n〃);return;

)

cur二xmlDocGetRootElement(doc);〃確定文檔根元素

/*檢查確認(rèn)當(dāng)前文檔中包含內(nèi)容*/

if(cur二二NULL){fprintf(stderr,,"emptydocument\nz,);

xmlFreeDoc(doc);return;

/*在這個(gè)例子中,我們需要確認(rèn)文檔是正確的類型?!皉oot”是在

這個(gè)例如中使用文檔的根類型。*/

if(xmlStrcmp(cur->name,(constxmlChar*)11rootf,)){

fprintf(stderr,'documentofthewrongtype,rootnode!=

root");xmlFreeDoc(doc);

return;

)

cur=cur->xmlChiIdrenNode;

while(cur!=NULL){if((!xmlStrcmp(cur->name,(constxmlChar*)

“keyword")))

key=xmlNodeListGetString(doc,cur->xmlChiIdrenNode,

1);printf(''keyword:%s\n〃,key);

xmlFree(key);)

cur=cur->next;

xmH?reeDoc(doc);

<SYSTEMNAME>IVMdows</SYSTEMNAME>

<SYSTEMTYPE>W/ndows</SYSTEMTYPE>

<LOGPATH></LOGPATH>

<LOGFORMAT></LOGFORMAT>

<ACTION>Sys/og</ACTION>

<ACTIONPARAM>

<PARAM>采集機(jī)IP</PARAM>

<PARAM>514</PARAM>

<PARAM>/oca/0</PARAM>

</ACTIONPARAM>

</SYSTEM>

重新啟動事件收集程序即“J。

網(wǎng)絡(luò)設(shè)備日志配置方法Cisco交換機(jī)、

路由器

device#conft

device(config)#loggingon

device(config)#logging采集機(jī)IP地址〃采集機(jī)IP地址

device(config)#loggingtraperrf)日志記錄級另ll,可用〃?”查看詳細(xì)內(nèi)容

device(config)#servicetimestampslogdatetimelocaltime〃日志t己錄時(shí)間戳設(shè)

置檢驗(yàn)

device#shlogging華為交換機(jī)、路由器

device#info-centerenable

device#info-centerloghost聚集機(jī)IP地址〃米集機(jī)IP地址平安設(shè)備H志和

SNMP配置方法

3、修改XML元素及屬性等信息

要修改XML文檔里的元素及屬性等信息,先需要解析XML文檔,獲得

一個(gè)節(jié)點(diǎn)指針(xmlNodePtrnode),利用該節(jié)點(diǎn)指針漫游DOM樹,就可以

在XML文檔中獲取,修改,添加相關(guān)信息。

例如3:

得到一個(gè)節(jié)點(diǎn)的內(nèi)容:

xmlCharlvalue=xmlNodeGetContent(node);返回值value應(yīng)該使

用xmlFree(value)釋放內(nèi)存

得到一個(gè)節(jié)點(diǎn)的某屬性值:

xmlCharlvalue=xmlGetProp(node,(constxmlChar*)11prop]〃);

返回值需要xmlFree(value)釋放內(nèi)存

設(shè)置一個(gè)節(jié)點(diǎn)的內(nèi)容:

xmlNodeSetContent(node,(constxmlChar*)〃testf,);設(shè)置一

個(gè)節(jié)點(diǎn)的某屬性值:

xmlSetProp(node,(constxmlChar*)〃propl〃,(constxmlChar

*)〃vl〃);

添加一個(gè)節(jié)點(diǎn)元素:

xmlNewTextChild(node,NULL,(constxmlChar*)“keyword”,

(constxmlChar*)〃testElement");

添加一個(gè)節(jié)點(diǎn)屬性:

xmlNewProp(node,(constxmlChar*)11propl〃,(constxmlChar

*)"testProp");

4、查找XML節(jié)點(diǎn)

有時(shí)候?qū)σ粋€(gè)XML文檔我們可能只關(guān)心其中某一個(gè)或某幾個(gè)特定的

Element的值或其屬性,如果漫游D0M樹將是很痛苦也很無聊的事,

利用XPath可以非常方便地得到你想的Elemento下面是一個(gè)自定義函

數(shù):

例如4:

xmlXPathObjectPtrgetnodeset(xmlDocPtrdoc,const

xmlChar*xpath){

xmlXPathContextPtrcontext;xmlXPathObjectPtrresult;

context=xmlXPathNewContext(doc);if(context二二NULL){

printf(^contextisNULL\n〃);returnNULL;

}result=xmlXPathEvalExpression(xpath,context);

xmlXPathFreeContext(context);if(result二二NULL){

printf("xmlXPathEvalExpressionreturnNULL\n〃);return

NULL;)

if(xmlXPathNodeSetlsEmpty(result->nodesetval))

{xmlXPathFreeObject(result);printf("nodesetis

empty\n〃);

returnNULL;returnresult;

)

在doc指向的XML文檔中查詢滿足xpalh表達(dá)式條件的節(jié)點(diǎn),返回

滿足這一條件的節(jié)點(diǎn)集合查詢條件xpath的寫法參見xpath相關(guān)資

料。在查詢完畢獲取結(jié)果集后,就可以通過返回的xmlXPathObjectPtr

結(jié)構(gòu)訪問該節(jié)點(diǎn):

例如5:

xmlChar*xpath=C7root/node/[@key=,keywords]zz);

xmlXPathObjectPtrappresult=getncdeset(doc,xpath);

if(appresult==NULL){printf("appresultisNULL\n〃);

return;

)

inti=0;

xmlCharlvalue;

if(appresult){xmlNodeSetEtrnodeset=app_result->nodesetval;

for(i=0;i<nodeset->nodeNr;i++){

cur=nodeset->nodeTab[i];cur=cur->xmlChiIdrenNode;

while(cur!=NULL){value=xmlGetProp(cur,(constxmlChar

*)〃key〃);

if(value!=NULL){

printf("value:%s\n\n〃,dConvertCharset(zutf-8z,〃

GBK〃,(char*)value));xmlFree(value);

}value=xmlNodeGetContent(cur);

if(value!=NULL){

printf("value:%s\n\n〃,dConvertCharset(〃utf-8〃,//

GBK〃,(char*)value));xmlFree(value);

xmlXPathFreeObject(appresult);

通過get_nodeset()返回的結(jié)果集,我們可以獲取該節(jié)點(diǎn)的元素及

屬性,也可以修改該節(jié)點(diǎn)的值。例如中在獲取值打印的時(shí)候用到

c_ConvertCharset0函數(shù)來改變編碼格式為GBK,以方便正確讀取可能

的中文字符。

5、編碼問題

由于Libxml一般以UTF-8格式保存和操縱數(shù)據(jù),如果你的程序使用

其它的數(shù)據(jù)格式,比方中文字符(GB2312,GBK編碼),就必須使用Libxml

函數(shù)轉(zhuǎn)換到UTF-8o如果你想你的程序以除UTF-8外的其它編

碼方式輸出也必須做轉(zhuǎn)換。

下面的例如程序提供幾個(gè)函數(shù)來實(shí)現(xiàn)對數(shù)據(jù)編碼格式的轉(zhuǎn)換,

其中有的要用到Libiconv,因此為了確保他們能正常工作,先

檢查以下系統(tǒng)中是否已經(jīng)安裝libiconv庫。

例如6:

xmlChar*ConvertInput(constchar*in,constchar

^encoding)unsignedchar*out;

intret;intsize;

intoutsize;inttemp;

xmlCharEncodingHandlerPtrhandler;if(in二二0)

return0;hander=xmlFindCharEncodingHandler(encoding);

if(!handler){printf(zConvertInput:noencodinghandler

foundfor

‘%s'\n〃,encoding?encoding:〃11);return0;

}size=(int)strlen(in)+1;

out_size=size*2-1;out=(unsignedchar*)

xmlMalloc((size_t)out_size);

if(out!=0){temp=size-1;

ret二handler->input(out,&out_size,(constunsignedchar*)

in,&temp);if((ret<0)|(temp-size+1)){

if(ret<0){

printf(Tonvertlnput:conversionwasn'tsuccessful.

\n〃):}else{

printf(Z/Convertlnput:conversionwasn'tsuccessful,

converted:%ioctets.\n〃,temp);)

xmlFree(out);out=0;

}else{out=(unsignedchar*)xmlRealloc(out,outsize+

1);

out[out_size]=0;Anu11terminatingout*/}

}else(printf("ConvertInput:nomem\nz);

}returnout;

例如7:

char*Convert(char*encFrom,char*encTo,constchar求

in)staticcharbufin'1024],bufout[1024],*sin,*sout;

intmode,lenin,lenout,ret,nline;iconv_tc_pt;

if((c_pt=iccnvopen(encTo,encFrom))==(iconvt)-l)(

printf(ziconv_openfalse:%s==>%s\n〃,encFrom,encTo);

returnNULL;}

iconv(c_pt,NULL,NULL,NULL,NULL);lenin=strlen(in)+1;

lenout=1024;sin=(char*)in;

sout=bufout;

ret=iconv(cpt,&sin,(sizet*)&lenin,fesout,(sizet

*)&lenout);if(ret=二T){returnNULL;

)iconvclose(c_pt);

returnbufout;

例如8:

chardConvertCharset(char*cpEncoceFrom,charcpEncodeTo,

constchar*cplnput){staticcharsstrBufOut[1024],*sin,*cp0ut;

size_tilnputLen,iOutLen,iReturn;iconvtc_pt;

if((c_pt=iconv_open(cpEncodeTo,cpEncodeFrom))==

(iconv_t)-l){printf(ziconv_openfailed!\nz);

returnNULL;}

iconv(c_pt,NULL,NULL,NULL,NULL);ilnputLen=

strlen(cplnput)+1;

iOutLen=1024;sin=(char*)cplnput;

cpOut=s_strBufOut;iReturn=iconv(c_pt,&sin,&iInputLen,

&cpOut,feiOutLen);

CiscoPIX防火墻Syslog配置方法

1.device#conftdevice(config)#loggingon

device(config)#logginghost采集機(jī)Ip地址〃采集機(jī)IP地址

device(config)#loggingtrapnotifdevice#sh〃設(shè)置日志級別

loggingDevice#writememorySNMP配置方法〃檢驗(yàn)設(shè)置

〃保存配置

1.device#conft

2.device(config)#snmp-serverhost采集機(jī)IP地址communityisone

3.device(config)#snmp-serverhost采集機(jī)IP土也址

4.device#shlogging

5.writememory注:isone為communityname請根據(jù)實(shí)際情況填寫

Netscreen防火墻Syslog配置方法

l.setsyslogconfig采集機(jī)IP地址Iocal4Iocal4”采集機(jī)IP地址

2.setsyslogenable

3.setsyslogtraffic(此命令可能沒有)

4.setlogmodulesystemlevelnotifdestinationsyslog

5.saveSNMP配置方法

1.Setsnmpcommunityisone采集機(jī)IP地址

2.Setsnmpcomm

溫馨提示

  • 1. 本站所有資源如無特殊說明,都需要本地電腦安裝OFFICE2007和PDF閱讀器。圖紙軟件為CAD,CAXA,PROE,UG,SolidWorks等.壓縮文件請下載最新的WinRAR軟件解壓。
  • 2. 本站的文檔不包含任何第三方提供的附件圖紙等,如果需要附件,請聯(lián)系上傳者。文件的所有權(quán)益歸上傳用戶所有。
  • 3. 本站RAR壓縮包中若帶圖紙,網(wǎng)頁內(nèi)容里面會有圖紙預(yù)覽,若沒有圖紙預(yù)覽就沒有圖紙。
  • 4. 未經(jīng)權(quán)益所有人同意不得將文件中的內(nèi)容挪作商業(yè)或盈利用途。
  • 5. 人人文庫網(wǎng)僅提供信息存儲空間,僅對用戶上傳內(nèi)容的表現(xiàn)方式做保護(hù)處理,對用戶上傳分享的文檔內(nèi)容本身不做任何修改或編輯,并不能對任何下載內(nèi)容負(fù)責(zé)。
  • 6. 下載文件中如有侵權(quán)或不適當(dāng)內(nèi)容,請與我們聯(lián)系,我們立即糾正。
  • 7. 本站不保證下載資源的準(zhǔn)確性、安全性和完整性, 同時(shí)也不承擔(dān)用戶因使用這些下載資源對自己和他人造成任何形式的傷害或損失。

評論

0/150

提交評論