2016-12-29 34 views
0

我是Groovy腳本的新手,我正在處理自定義腳本。在調試/跟蹤模式下測試我得到這個錯誤:groovy腳本:沒有類錯誤的此類屬性

2016-12-29 12:26:50,913 [pool-4467-thread-1]錯誤ENI-callMDC.invoke0(?) - >> setAdminGroup>無法設置CA ENI-AdminGroup。 原因:沒有這樣的屬性:ucmdbcacheDumpFile類:ENIcallMDC

這裏完整的腳本,其中顯示兩個所涉及的功能:

*

* 
import java.util.List; 
import java.util.Date; 
import java.util.Map; 
import java.util.HashMap; 
import java.util.Iterator; 
import java.util.UUID; 
import java.io.File; 
import java.io.PrintWriter; 
import java.io.FileReader; 
import java.io.BufferedReader; 
import java.util.regex.Matcher; 
import java.util.regex.Pattern; 
import java.util.TimerTask; 
import java.util.Timer; 
import com.hp.opr.api.scripting.Event 
import com.hp.opr.api.scripting.Severity 
import com.hp.opr.api.scripting.LifecycleState 
import com.hp.opr.api.scripting.UcmdbServiceProvider 
import com.hp.ucmdb.api.UcmdbService 
import com.hp.ucmdb.api.topology.QueryDefinition 
import com.hp.ucmdb.api.topology.Topology 
import com.hp.ucmdb.api.topology.TopologyQueryFactory 
import com.hp.ucmdb.api.topology.TopologyQueryService 
import com.hp.ucmdb.api.types.TopologyCI 
import com.hp.ucmdb.api.types.UcmdbId 
import com.hp.ucmdb.api.classmodel.ClassModelService 
import com.hp.ucmdb.api.classmodel.ClassDefinition 
import com.hp.ucmdb.api.classmodel.Attribute 
import org.apache.commons.logging.Log 
import org.apache.commons.logging.LogFactory 
// Libraries for HTTP GET call 
import org.apache.http.HttpRequest; 
import groovyx.net.http.HTTPBuilder; 
//import static groovyx.net.http.Method.GET; 
import groovyx.net.http.Method; 
//import static groovyx.net.http.ContentType.TEXT; 
import groovyx.net.http.ContentType; 

class ENIcallMDC 
{ 
    private Log s_log = LogFactory.getLog("ENI-callMDC") 
    UcmdbServiceProvider ucmdbServiceProvider 
    UcmdbService ucmdbServiceAccess = null 
    public Map<String, Map<String,String>> dataSHM       // Global HashMap for CIs 
    //public Map<String,String> catHashMap         // Global HashMap for Category suffixes - Rimane locale solo nella init - non serve globale 
    public Map<String, Map<String,String>> ucmdbCache 
    public static final long REFRESH_INTERVAL = 3600;      // in seconds 
    public static final long EVT_PIPELINE_WAITING_TIMEOUT = 300;    // in seconds 
    public static final int MAX_CHUNK_SIZE = 20;        // in number of events 
    public static final String rtsmTQL = "ENI-OPR-callMDC";     // TQL for CIs which are mapped on events - attributes of interest are defined in TQL element layout 

    public static final String ciTypeCaName  = "ENI-CItype";   // Event Custom Attribute for OStype/CIT 
    public static final String ciTypeAttrName  = "discovered_os_name"; // Attribute name for Discovered OS Name   // in data struct 
    public static final String adminGroupCaName = "ENI-AdminGroup";  // Event Custom Attribute for Gruppo di gestione 
    public static final String adminGroupAttrName = "tools_admin_group";  // Attribute name for Gruppo di Gestione   // in data struct 
    public static final String locationCaName  = "ENI-Location";   // Event Custom Attribute for Location 
    public static final String locationAttrName = "calculated_location"; // Attribute name for Location      // in data struct 
    public static final String tagsCaName   = "ENI-Tags";    // Event Custom Attribute for Tags 
    public static final String tagsAttrName  = "tags_string";   // Attribute name for Tags       // in data struct   

    public static final String citAttrName = "root_class";     // Attribute name for CIT 
    public static final String CITgroup = "CITgroup";      // Attribute for CIT group      // in data struct 

    public boolean enableEvtHandler = false;         // Global var for enable EVT handling (once HashMaps are calculated) 
    public boolean threadHasToStop = false 
    public Thread myThread = null 

    public static final String ucmdbCacheDumpFile = "F:\\HPBSM\\Temp\\ENI-HandleIncomingEventsAR-ExtUcmdbCache.dump"; 

    // MDC parameters are in callMDC method 


    def init() 
    { 
    .....  
    } 

    def destroy() 
    { 
    .... 
    } 

    def synchronized initUcmdbService() { 
    .... 
    } 

    def synchronized getMap() { 
     ......... 
    } 


    def process(List<Event> events) { 
     ..... 
    } 
    def setEniCItype(Event evt,String relCiID) { 
     ..... 
    } 
    def setAdminGroup(Event evt,String relCiID) { 
     try { 
      String myEvtTitle = evt.getTitle(); 
      // DISCRIMINAZIONE TIPO FILE SYSTEM - codice preso da ENI-HandleIncomingEventsAR.groovy a riga #1183 
      if (myEvtTitle.contains("File System ")) { 
       s_log.debug("Process >   >> setAdminGroup > RelCI is Node > FS event > checking FS name"); 
       createUcmdbCache() 
       String myFsName; 
       Pattern omlAllPattern = Pattern.compile("^File\\s+System\\s+\\<([^:]+):?\\>\\s+on\\s+server\\s+"); // from OML win|lnx 
       Matcher omlAllMathcer = omlAllPattern.matcher(myEvtTitle); 
       s_log.trace("Process >   >> setAdminGroup > RelCI is Node > FS event > checking FS name > checking OML win|lnx regex"); 
       if (omlAllMathcer.find()) { 
        myFsName=omlAllMathcer.group(1); 
        s_log.trace("Process >   >> setAdminGroup > RelCI is Node > FS event > checking FS name > checking OML win|lnx regex > matched FS: " + myFsName); 
       } else { 
        s_log.trace("Process >   >> setAdminGroup > RelCI is Node > FS event > checking FS name > checking OML win|lnx regex > NOT matched"); 
        s_log.trace("Process >   >> setAdminGroup > RelCI is Node > FS event > checking FS name > checking SIS lnx regex"); 
        Pattern sisLnxPattern = Pattern.compile("^File\\s+System\\s+\\'Disk\\/File System\\/\\[.+\\((.+)\\)\\s*\\]\\/percent\\s+full\\'\\s+on\\s+server\\s+"); // from SIS lnx 
        Matcher sisLnxMathcer = sisLnxPattern.matcher(myEvtTitle); 
        if (sisLnxMathcer.find()) { 
         myFsName=sisLnxMathcer.group(1); 
         s_log.trace("Process >   >> setAdminGroup > RelCI is Node > FS event > checking FS name > checking SIS lnx regex > matched FS: " + myFsName); 
        } else { 
         s_log.trace("Process >   >> setAdminGroup > RelCI is Node > FS event > checking FS name > checking SIS lnx regex > NOT matched"); 
         s_log.trace("Process >   >> setAdminGroup > RelCI is Node > FS event > checking FS name > checking SIS win regex"); 
         Pattern sisWinPattern = Pattern.compile("^File\\s+System\\s+\\'Disk\\/File System\\/\\[([^\\(]+):?\\]\\/percent\\s+full\\'\\s+on\\s+server\\s+"); // from SIS win 
         Matcher sisWinMathcer = sisWinPattern.matcher(myEvtTitle); 
         if (sisWinMathcer.find()) { 
          myFsName=sisWinMathcer.group(1); 
          s_log.trace("Process >   >> setAdminGroup > RelCI is Node > FS event > checking FS name > checking SIS win regex > matched FS: " + myFsName); 
         } else { 
          s_log.trace("Process >   >> setAdminGroup > RelCI is Node > FS event > checking FS name > checking SIS win regex > NOT matched"); 
         } 
        } 
       } 
       if ((myFsName != null) ) { 
        try { 
         // se myFsName non è nullo allora l'admin group viene settato come il valore admin group presente nella hashmap ucmdbCache 
         String adminGrp = ucmdbCache.get(relCiID).get(myFsName) 
         // se l'admin group appena settato è nullo (quindi il file system non è stato trovato nella cache ucmdbCache) 
         if(adminGrp==null){ 
          // l'admin group viene settato col valore del padre >> comportamento di ENI-callMDC originale (v 1.1.1) 
          adminGrp = dataSHM.get(relCiID).get(adminGroupAttrName); 
         } 
         evt.addCustomAttribute (adminGroupCaName,adminGrp); 
         return; // nothing else to do 
        } catch (Exception e) { 
         s_log.error("  >> setAdminGroup > Error: " + e.getMessage()); 
        } 
       } else { 
       // if I was not able to extract FS name I don\'t return: fall back to node 
       } 
      } 
      if (dataSHM.containsKey(relCiID)) { 
       if (dataSHM.get(relCiID).get(CITgroup) == "business_application") { // Not have to calculate if CIT is BA 
        s_log.debug("  >> setAdminGroup > RelatedCI is BusinessApplication > nothing to do"); 
        return; 
       } 
       String adminGrp = dataSHM.get(relCiID).get(adminGroupAttrName); 
       evt.addCustomAttribute (adminGroupCaName,adminGrp); 
       s_log.debug("  >> setAdminGroup > Added CA " + adminGroupCaName + " = " + adminGrp);     
      } else { 
       s_log.debug("  >> setAdminGroup > RelatedCI " + relCiID + " is not present in cache > returning"); 
       return; 
      }    
     } catch (Exception e) { 
      s_log.error("  >> setAdminGroup > Failed to set CA " + adminGroupCaName + ". Reason: " + e.getMessage()); 
     } 
    } 
    def setTags(Event evt,String relCiID) { 
     ...... 
    } 
    def setLocation(Event evt, String relNodeID) { 
     ... 
    } 

    def callMDC(String evtID) { 
     .... 
    } 
    def synchronized createUcmdbCache() { 
     try { 
      Map<String, Map<String,String>> localHM = new HashMap() 
      String line 
      // leggo dal ucmdb cache file 
      FileReader fr = new FileReader(ucmdbcacheDumpFile) 
      BufferedReader textReader = new BufferedReader(fr) 
      // creazione della hashmap annidata 
      while((line = textReader.readLine()) != null) { 
       String[] parts = line.split("~") 
       // parts[0]=relatedCI 
       // parts[1]=File System Type 
       // parts[2]=Admin group 
       if (localHM.containsKey(parts[0])) { 
        // tempHM = mappa più interna che contiene FileSystemTipe,AdminGroup 
        Map<String,String> tempHM = localHM.get(parts[0]) 
        tempHM.put(parts[1], parts[2]) 
        localHM.put(parts[0],tempHM) 
       } 
       else { 
        Map<String,String> tempHM = new HashMap() 
        tempHM.put(parts[1], parts[2]) 
        // aggiunta alla hashmap più esterna di RelatedCI,(tempHM) dove tempHM=FileSystemTipe,AdminGroup 
        localHM.put(parts[0],tempHM) 
       } 
      } 
      textReader.close() 
      // set variabile globale ucmdbCache con il valore della hashmap localHM 
      ucmdbCache = Collections.synchronizedMap(localHM) 
     } catch (IOException e) { 
     } 
    } 
} 
* 

*

我已經定義ucmdbCacheDumpFile作爲腳本頂部的公共靜態最終字符串:

*`public static final String ucmdbCacheDumpFile = "F:\\HPBSM\\Temp\\ENI-HandleIncomingEventsAR-ExtUcmdbCache.dump";`* 

我認爲這個錯誤與這個定義有關。你有什麼建議嗎?我需要以不同的方式設置嗎?

感謝與問候,

的Fab

+1

那你ENIcallMDC類。它有一個名爲cacheDumpFile的屬性嗎? –

+0

Hello Emmanuel, – Fab

+0

我剛剛編輯上傳完整腳本的初始問題(僅關注兩個涉及函數)。考慮我已經定義了屬性ucmdbcacheDumpFile(我已經重命名爲)公共靜態最終字符串。夠了嗎?我需要以不同的方式設置它嗎?問候,Fab – Fab

回答

0

我想告訴我已經解決了我的錯誤,從改變:

String adminGrp = ucmdbCache.get(relCiID).get(myFsName) 

String adminGrp = ucmdbCache.get(myNodeNameHint).get(myFsName) 

因爲relCIID值沒有出現在我的散列表中和設置以及我的新的字符串:

String myNodeNameHint = evt.getRelatedCiHint(); 

問候, 的Fab

相關問題