2016-12-19 56 views
1

我不得不問駱駝路由行爲,這是愚蠢的(但很容易理解)邏輯描述。 在主要主題 - 我需要將信息從一個路由的交換頭部推送到另一個路由。 這是關於CMDB系統和監控工具zabbix。 那麼,在第一次我有可能在CMDB切換CI狀態的路線:Apache駱駝:從交換頭到另一個路由的數據

<route> 
    <description> route catching CI ID in jms queue, check it on exist and switch CI state to incident 
    </description> 
    <from uri="jms:switchCIStateQueue"/> 
    <filter> 
     <simple>${body} regex '[\d]+'</simple> 
     <to uri="bean:otrsCIApi?method=getCIBodyByID(${body})"/> 
     <filter> 
      <simple>${body} regex '\{.+?\}'</simple> 
      <marshal> 
       <json library="Jackson"/> 
      </marshal> 
      <unmarshal> 
       <json library="Jackson" unmarshalTypeName="ts.team.otrs.ci.OtrsCI"/> 
      </unmarshal> 
      <to uri="bean:otrsCIApi?method=switchOTRSCIState(${body})"/> 
     </filter> 
    </filter> 
</route> 

它的工作好,但我必須從另外的路線,這有很多的檢查,過濾器和選擇使用這個動作。 我的問題是,我沒有一個身份證件身份(但保持在標題)在主要邏輯路線的深度。

<route> 
    <description>Route catch triggerid 
    and creates a ticket in OTRS, link it to host 
    </description> 
    <from uri="direct:zab_trig_2_otrs_tick"/> 
    <to uri="bean:zabbixApi?method=getTriggerByID(body)"/> 
    <filter> 
     <simple>${body} regex '\{.+?\}'</simple> 
      <marshal> 
       <json library="Jackson"/> 
      </marshal> 
      <unmarshal> 
       <json library="Jackson" unmarshalTypeName="ts.team.zabbix.trigger.SingleTrigger"/> 
      </unmarshal> 
      <setHeader headerName="ZabbixTrigger" id="_setZabbixTrigger"> 
       <simple>${body}</simple> 
      </setHeader> 
      <!-- search CI in OTRS --> 
      <to uri="bean:otrsCIApi?method=searchCI(${body.getHosts().get(0).getName()})"/> 
      <!-- Array of CI ID like [] or ["1"] --> 
      <split streaming="true"> 
       <simple>${body}</simple> 
       <!-- place it in header--> 
       <setHeader headerName="HostID"> 
        <simple>${body}</simple> 
       </setHeader> 
       <to uri="bean:otrsLinkApi?method=ListLinkedTicketsTitleFiltered(${body},${header.ZabbixTrigger.getDescription()})"/> 
       <!-- return JSONArray with State=open otrs Tickets ID --> 
       <choice> 
        <when id="ticketslist_empty"> 
         <simple>${body} == ''</simple> 
         <!-- Create ticket, connect it to host in OTRS --> 
         <to uri="bean:otrsTicketApi?method=createNewTicket(${header.ZabbixTrigger.getDescription()},${header.ZabbixTrigger.getPriority()})"/> 
         <!-- return body body with ticket id, create link with ${header.HostID} --> 
         <to uri="bean:otrsLinkApi?method=LinkAdd(${header.HostID},${body})"/> 
         <!-- Here i need to switch CI state if incident priority is higher than 3(Normal)--> 
         <when> 
          <simple>${header.ZabbixTrigger.getPriority()} > 3</simple> 
          <!-- here i need to send ${header.HostID} to previous described route (jms:switchCIStateQueue)--> 
         </when> 
        </when> 
       </choice> 
      </split> 
    </filter> 
</route> 

因此,有一塊這條路線的:

    <when> 
         <simple>${header.ZabbixTrigger.getPriority()} > 3</simple> 
         <!-- here i need to send ${header.HostID} to previous described route (jms:switchCIStateQueue)--> 
        </when> 

,我需要從我的頭髮送一些信息給JMS:switchCIStateQueue(或途徑直接,這是無論在哪裏)。 我希望,我對問題的描述很全面和簡單。

+0

不幸的不是:)什麼是問題?什麼阻止你把$ {header.HostID}放到$ {body}中,正如「前面描述的路由」所預計的那樣?或者相反,不要從$ {body}中獲取CID,而要從該路由中的標題中獲取CID? – Vadim

+0

@Vadim,謝謝你的評論。我很抱歉在我的描述中如此粗魯。主要問題是什麼 - 我需要將CIID推入第一個描述的路線。我抓不住,我怎麼能把它做到我的大路上。原因需要將CIID放在標題$ {header.HostID}中而不是正文。我如何將$ {header.HostID}放入正文? – smartydoc

+0

我的意思是,我不知道正確的方式將信息從$ {header.HostID}放置到jms:switchCIStateQueue。如果你有一些想法,我會很樂意閱讀它:) – smartydoc

回答

1

好的。 你問了兩個問題:

  1. 我需要推CIID到首次描述路線

你推一個JMS消息jms:switchCIStateQueue 所以,在你的源路由(第二個「大牌」)應該是這樣的:

<to uri="jms:switchCIStateQueue"/> 

無論在Exchange頭文件中都將在JMS消息頭中。 Exchange郵件正文將是JMS郵件正文。 如果你會做它用代碼源路由的是,將會有JMS頭HostID,你的第一途徑,其獲取JMS消息也可以存取${header.HostID}

然後取決於你otrsCIApi.getCIBodyByID期待並做您的來電可能看起來像

a。 <to uri="bean:otrsCIApi?method=getCIBodyByID(${header.HostID})"/>

b。但是,如果'getCIBodyByID'的預期參數具有不同於更多CIID的結構/格式,則必須在將其發送到隊列時(以「大」路徑)或從隊列中獲取消息後正確構建它。

  • 如何可以將$ {header.HostID}成體

  • 再次它取決於什麼是預期JMS的結構/格式

    消息body

    a。只需將HostID標頭值置於正文中即可:

    <when> 
        <simple>${header.ZabbixTrigger.getPriority()} > 3</simple> 
         <!-- here i set ${header.HostID} into body --> 
         <body> 
         <simple>${header.HostID}</simple> 
         </body> 
         <!-- here i can set ${header.HostID} into another header if i'd like to --> 
         <setHeader headerName="CIID"> 
             <simple>${header.HostID}</simple> 
         </setHeader> 
         <!-- finally I send message to queue --> 
         <to uri="jms:switchCIStateQueue"/> 
    </when> 
    

    b。不僅僅是CIID值 - 根據需要構建它(代替<body>元素,可能會有處理器或其他bean方法調用會這樣做)

    我是否正確理解您的問題並且它是您正在查找的內容?

    +0

    瓦迪姆,非常感謝你!我嘗試使用第一種方法 - 在其他路由中使用簡單的和期望$ {header.HostID},但它變爲空。很奇怪,我想。然後我檢查你的建議,有關設置 $ {} header.HostID而且這也並非我:(作品。所以,我決定來計算所需的主機ID(相當於CIID)使用方法調用和標題信息,然後發送它以另一條路線 – smartydoc

    +0

    作爲補充,我的最後幾行看起來像<到URI = 「豆:otrsCIApi方法= searchCI($ {。header.ZabbixTrigger.getHosts()得到(0).getName()})」/ > <到URI =「JMS:switchCIStateQueue」 />謝謝你的建議,這使我很粗糙,但工作的解決方案,我認爲,我的例外是綁定在camel.xml依賴或描述春天模式 – smartydoc

    +1

    你是。實際上,爲什麼我不使用這些技術,並且總是通過處理器或者Java方法調用需要的工作,沒有足夠的關於特定事物的明確文檔和一些限制在那裏可以使用什麼和哪裏可以使用...還有簡單的Java性能要好得多。祝你好運。 – Vadim