private static WBXXml createHealthReport( string agentType, string agentUID, string agentVersion, string agentConfigId ) { WBXXml result = new WBXXml(_baseHealthXML); // Update the agent uid in the xml result.updateFirstNameValue( "uid", agentUID ); // Update the agent type in the xml result.updateFirstNameValue( "type", agentType ); // Update the agent version in the xml result.updateFirstNameValue( "version", agentVersion ); // Update the agent config id in the xml result.updateFirstNameValue( "configid", agentConfigId ); return(result); }
private static string createEventXMLForWPCDataFetch( string dateTime, string ipAddress, string username ) { WBXXml xmlResult = new WBXXml(); // Add Policy Data Element xmlResult.addElement( null, Constants.WBX_XML.XML_POLICY_DATA_ELEMENT_NAME ); // Add the timestamp property xmlResult.addPair( Constants.BASE_EVENT_XML_FIELDS.TIME_STAMP.FATHER_ELEMENT, Constants.BASE_EVENT_XML_FIELDS.TIME_STAMP.NAME, dateTime ); // Add the IP Address property xmlResult.addPair( Constants.BASE_EVENT_XML_FIELDS.IP_ADDRESS.FATHER_ELEMENT, Constants.BASE_EVENT_XML_FIELDS.IP_ADDRESS.NAME, ipAddress ); // Add the username property xmlResult.addPair( Constants.BASE_EVENT_XML_FIELDS.USER_NAME.FATHER_ELEMENT, Constants.BASE_EVENT_XML_FIELDS.USER_NAME.NAME, username ); return(xmlResult.ToString()); }
private static void addWSSEvent( WBXXml eventsXMLToSend, string eventXPath, Hashtable pairNameHsh, string[] eventDetails ) { string tempStr = null; #region Add business data string businessDataXPath = eventXPath + "/businessdata"; #region Business Service Origin tempStr = eventDetails[(int)pairNameHsh["businessServiceOrigin"]]; if (!string.IsNullOrEmpty(tempStr)) { eventsXMLToSend.addPair( businessDataXPath, "businessServiceOrigin", tempStr ); } #endregion #region Item Location tempStr = eventDetails[(int)pairNameHsh["itemLocation"]]; if (!string.IsNullOrEmpty(tempStr)) { eventsXMLToSend.addPair( businessDataXPath, "itemLocation", tempStr ); } #endregion #endregion #region Add policy data string policyDataXPath = eventXPath + "/policydata"; #region User Action tempStr = eventDetails[(int)pairNameHsh["userAction"]]; if (!string.IsNullOrEmpty(tempStr)) { eventsXMLToSend.addPair( policyDataXPath, "userAction", tempStr ); } #endregion #region User Agent tempStr = eventDetails[(int)pairNameHsh["userAgent"]]; if (!string.IsNullOrEmpty(tempStr)) { eventsXMLToSend.addPair( policyDataXPath, "userAgent", tempStr ); } #endregion #region Authentication tempStr = eventDetails[(int)pairNameHsh["authentication"]]; if (!string.IsNullOrEmpty(tempStr)) { eventsXMLToSend.addPair( policyDataXPath, "authentication", tempStr ); } #endregion #region Custom Action tempStr = eventDetails[(int)pairNameHsh["customAction"]]; if (!string.IsNullOrEmpty(tempStr)) { eventsXMLToSend.addPair( policyDataXPath, "customAction", tempStr ); } #endregion #region Item Id tempStr = eventDetails[(int)pairNameHsh["itemId"]]; if (!string.IsNullOrEmpty(tempStr)) { eventsXMLToSend.addPair( policyDataXPath, "itemId", tempStr ); } #endregion #region Item Type tempStr = eventDetails[(int)pairNameHsh["itemType"]]; if (!string.IsNullOrEmpty(tempStr)) { eventsXMLToSend.addPair( policyDataXPath, "itemType", tempStr ); } #endregion #region Event Data tempStr = eventDetails[(int)pairNameHsh["eventData"]]; if (!string.IsNullOrEmpty(tempStr)) { eventsXMLToSend.addPair( policyDataXPath, "eventData", tempStr ); } #endregion #region Event Source tempStr = eventDetails[(int)pairNameHsh["eventSource"]]; if (!string.IsNullOrEmpty(tempStr)) { eventsXMLToSend.addPair( policyDataXPath, "eventSource", tempStr ); } #endregion #region Location Type tempStr = eventDetails[(int)pairNameHsh["locationType"]]; if (tempStr != null) { eventsXMLToSend.addPair( policyDataXPath, "locationType", tempStr ); } #endregion #region Ip Address tempStr = eventDetails[(int)pairNameHsh["IpAddress"]]; if (!string.IsNullOrEmpty(tempStr)) { eventsXMLToSend.addPair( policyDataXPath, "IpAddress", tempStr ); } #endregion #region Machine Name tempStr = eventDetails[(int)pairNameHsh["machineName"]]; if (tempStr != null) { eventsXMLToSend.addPair( policyDataXPath, "machineName", tempStr ); } #endregion #region TimeStamp tempStr = eventDetails[(int)pairNameHsh["TimeStamp"]]; if (tempStr != null) { eventsXMLToSend.addPair( policyDataXPath, "TimeStamp", tempStr ); } #endregion #region Site Id tempStr = eventDetails[(int)pairNameHsh["siteId"]]; if (!string.IsNullOrEmpty(tempStr)) { eventsXMLToSend.addPair( policyDataXPath, "siteId", tempStr ); } #endregion #region Source Name tempStr = eventDetails[(int)pairNameHsh["sourceName"]]; if (tempStr != null) { eventsXMLToSend.addPair( policyDataXPath, "sourceName", tempStr ); } #endregion #region User Name tempStr = eventDetails[(int)pairNameHsh["UserName"]]; if (!string.IsNullOrEmpty(tempStr)) { eventsXMLToSend.addPair( policyDataXPath, "UserName", tempStr ); } #endregion #region User Domain tempStr = eventDetails[(int)pairNameHsh["userDomain"]]; if (tempStr != null) { eventsXMLToSend.addPair( policyDataXPath, "userDomain", tempStr ); } #endregion #region WSS UserId tempStr = eventDetails[(int)pairNameHsh["wssUserId"]]; if (!string.IsNullOrEmpty(tempStr)) { eventsXMLToSend.addPair( policyDataXPath, "wssUserId", tempStr ); } #endregion #region User Domain tempStr = eventDetails[(int)pairNameHsh["wssGroups"]]; if (tempStr != null) { eventsXMLToSend.addMultiattribute( policyDataXPath, "wssGroups", tempStr.Split(Constants.MULTIATTRIBUTE_DELIMITER) ); } #endregion #endregion }
private static void addSAPR3Event( WBXXml eventsXMLToSend, string eventXPath, Hashtable pairNameHsh, string[] eventDetails ) { string tempStr = null; #region Add business data string businessDataXPath = eventXPath + "/businessdata"; #region Transaction ID tempStr = eventDetails[(int)pairNameHsh["TransactionId"]]; if (!string.IsNullOrEmpty(tempStr)) { eventsXMLToSend.addPair( businessDataXPath, "TransactionId", tempStr ); } #endregion #region Report Name tempStr = eventDetails[(int)pairNameHsh["ReportName"]]; if (!string.IsNullOrEmpty(tempStr)) { eventsXMLToSend.addPair( businessDataXPath, "ReportName", tempStr ); } #endregion #region Dynpro Number tempStr = eventDetails[(int)pairNameHsh["DynproNumber"]]; if (!string.IsNullOrEmpty(tempStr)) { eventsXMLToSend.addPair( businessDataXPath, "DynproNumber", tempStr ); } #endregion #endregion #region Add policy data string policyDataXPath = eventXPath + "/policydata"; #region Server Name tempStr = eventDetails[(int)pairNameHsh["ServerName"]]; if (!string.IsNullOrEmpty(tempStr)) { eventsXMLToSend.addPair( policyDataXPath, "ServerName", tempStr ); } #endregion #region Timestamp tempStr = eventDetails[(int)pairNameHsh["TimeStamp"]]; if (!string.IsNullOrEmpty(tempStr)) { eventsXMLToSend.addPair( policyDataXPath, "TimeStamp", tempStr ); } #endregion #region Ip Address tempStr = eventDetails[(int)pairNameHsh["IpAddress"]]; if (!string.IsNullOrEmpty(tempStr)) { eventsXMLToSend.addPair( policyDataXPath, "IpAddress", tempStr ); } #endregion #region Sap User tempStr = eventDetails[(int)pairNameHsh["SapUser"]]; if (!string.IsNullOrEmpty(tempStr)) { eventsXMLToSend.addPair( policyDataXPath, "SapUser", tempStr ); } #endregion #region Terminal Id tempStr = eventDetails[(int)pairNameHsh["TerminalId"]]; if (!string.IsNullOrEmpty(tempStr)) { eventsXMLToSend.addPair( policyDataXPath, "TerminalId", tempStr ); } #endregion #region Connection Type tempStr = eventDetails[(int)pairNameHsh["ConnectionType"]]; if (!string.IsNullOrEmpty(tempStr)) { eventsXMLToSend.addPair( policyDataXPath, "ConnectionType", tempStr ); } #endregion #region User Name tempStr = eventDetails[(int)pairNameHsh["UserName"]]; if (tempStr != null) { eventsXMLToSend.addPair( policyDataXPath, "UserName", tempStr ); } #endregion #endregion }
private static void sendEventsFromFile( string eventsFilename, PerformanceCounter counter, StreamWriter sw, int eventsInSend, int delayTime ) { #region Local variables Stopwatch stopWatch = new Stopwatch(); int eventsInXML = 0; WBXXml eventsXMLToSend = null; bool updateBAMInformation = true; string currBAMType = null; int eventsRead = 0; #endregion // Write the header line in the data collector file sw.WriteLine(DATA_COLLECTOR_FILE_HEADER_LINE); #region Open the events file FileStream fs = new FileStream( eventsFilename, FileMode.Open, FileAccess.Read ); StreamReader sr = new StreamReader(fs); #endregion #region Read and convert header names to hashtable // Read the XML names line in the events String[] pairNameArray = sr.ReadLine().Split(','); Hashtable pairNameHsh = new Hashtable(); for (int i = 0; i < pairNameArray.Length; i++) { pairNameHsh.Add(pairNameArray[i], i); } #endregion // Thread initialization complete // Increment the number of threads initialized. Interlocked.Increment(ref _threadsAreInitialized); // We want all the threads to start working together // so all threads will wait for the following variable // to be greater than zero. while (_threadsAreInitialized < _threadsCount) { Thread.Sleep(100); } Int64 totalTimeInMilliseconds; // Start reading events String currLine = sr.ReadLine(); // Read until all events are read while (currLine != null) { try { #region Create the XML to send if (eventsInXML == 0) { eventsXMLToSend = new WBXXml(BASE_EVENT); updateBAMInformation = true; } #endregion // Increment the event counters. eventsInXML++; eventsRead++; //counter.Increment(); string[] currLineArray = currLine.Split(','); #region Add a new event element // Create the event element eventsXMLToSend.addElement( null, "event", new Hashtable() { { "eventId", eventsInXML.ToString() } } ); string eventXPath = string.Format( "{0}[@{1}='{2}']", "event", "eventId", eventsInXML ); // Create the business data element in the event eventsXMLToSend.addElement( eventXPath, "businessdata" ); // Create the policy data element in the event eventsXMLToSend.addElement( eventXPath, "policydata" ); #endregion #region Update BAM information if needed if (updateBAMInformation) { currBAMType = currLineArray[(int)pairNameHsh["BAMType"]]; eventsXMLToSend.updateFirstNameValue( pairNameArray[(int)pairNameHsh["BAMType"]], currBAMType ); eventsXMLToSend.updateFirstNameValue( pairNameArray[(int)pairNameHsh["BAMUniqueID"]], currLineArray[(int)pairNameHsh["BAMUniqueID"]] ); updateBAMInformation = false; } #endregion #region Add event to the events XML switch (currBAMType.ToLower()) { case "sap r3": addSAPR3Event( eventsXMLToSend, eventXPath, pairNameHsh, currLineArray ); break; case "wss": addWSSEvent( eventsXMLToSend, eventXPath, pairNameHsh, currLineArray ); break; default: Console.WriteLine( "Unknown BAM type - {0}", currBAMType ); break; } #endregion #region Report the events to the event collector service // Report Events (maybe multi-threaded ?) if (eventsInXML == eventsInSend) { // Reset the number of events in the XML // before reading the next event eventsInXML = 0; stopWatch.Reset(); stopWatch.Start(); //Console.Out.WriteLine(eventsXMLToSend.ToString()); _serviceClient.reportEvents(eventsXMLToSend.ToString()); stopWatch.Stop(); totalTimeInMilliseconds = calculateTimeInMilliseconds( stopWatch.Elapsed ); // Update performance counter //counter.RawValue = stopWatch.Elapsed.Milliseconds; // Write the data to the data collector file sw.WriteLine( DATA_COLLECTOR_FILE_DATA_LINE, DateTime.Now.ToString(Constants.TIMESTAMP_FORMAT), totalTimeInMilliseconds ); // Flush the buffer sw.Flush(); Thread.Sleep(delayTime); } #endregion // Read the next event currLine = sr.ReadLine(); } #region Exception handling catch (Exception ex) { Console.WriteLine( "Error processing event number {0} from file {1}.\nError: {2}", eventsRead, eventsFilename, ex.Message ); } #endregion } sr.Close(); // Increment the number of threads finished. Interlocked.Increment(ref _numberOfThreadsFinished); }
private static string createEventXMLForWPCDataFetch( string dateTime, string ipAddress, string username ) { WBXXml xmlResult = new WBXXml(); // Add Policy Data Element xmlResult.addElement( null, Constants.WBX_XML.XML_POLICY_DATA_ELEMENT_NAME ); // Add the timestamp property xmlResult.addPair( Constants.BASE_EVENT_XML_FIELDS.TIME_STAMP.FATHER_ELEMENT, Constants.BASE_EVENT_XML_FIELDS.TIME_STAMP.NAME, dateTime ); // Add the IP Address property xmlResult.addPair( Constants.BASE_EVENT_XML_FIELDS.IP_ADDRESS.FATHER_ELEMENT, Constants.BASE_EVENT_XML_FIELDS.IP_ADDRESS.NAME, ipAddress ); // Add the username property xmlResult.addPair( Constants.BASE_EVENT_XML_FIELDS.USER_NAME.FATHER_ELEMENT, Constants.BASE_EVENT_XML_FIELDS.USER_NAME.NAME, username ); return xmlResult.ToString(); }
private static void runTestsForCase1and2( PerformanceCounter counter, StreamWriter sw, int iterationsCount, bool updateConfiguration, int delayTime ) { Stopwatch stopWatch = new Stopwatch(); string currentVersion = _current_agents_configuration_version.ToString(); // Write the header line in the data collector file sw.WriteLine(DATA_COLLECTOR_FILE_HEADER_LINE); // Increment the number of threads initialized. Interlocked.Increment(ref _threadsAreInitialized); // We want all the threads to start working together // so all threads will wait for the following variable // to be greater than zero. while (_threadsAreInitialized < _threadsCount) { Thread.Sleep(100); } Int64 totalTimeInMilliseconds; for (int i = 0; i < iterationsCount; i++) { // If we want to get a configuration update // we simply set the current version of the agent // configuration to -1 if (updateConfiguration) { currentVersion = "-1"; } #region Create the health reports // Go over each WPC agent and send his health report. foreach (string wpcAgentUID in _wpcUIDs.Keys) { // Create the health string to send WBXXml health = createHealthReport( Constants.AGENT_TYPES.WPC, wpcAgentUID, currentVersion, (string)_wpcUIDs[wpcAgentUID] ); // Reset the stop watch stopWatch.Reset(); stopWatch.Start(); // Send the health report to the agent // configuration manager. string healthResponse = _serviceClient.reportHealth( health.ToString() ); // Stop the stop watch stopWatch.Stop(); totalTimeInMilliseconds = calculateTimeInMilliseconds( stopWatch.Elapsed ); // Update performance counter //counter.RawValue = stopWatch.Elapsed.Seconds; // Check for an error if (healthResponse.IndexOf("error", 0, StringComparison.CurrentCultureIgnoreCase) > -1) { sw.WriteLine( DATA_COLLECTOR_FILE_ERROR_LINE, DateTime.Now.ToString(Constants.TIMESTAMP_FORMAT), wpcAgentUID, health.ToString() ); } else { // Write the data to the data collector file sw.WriteLine( DATA_COLLECTOR_FILE_DATA_LINE, DateTime.Now.ToString(Constants.TIMESTAMP_FORMAT), wpcAgentUID, totalTimeInMilliseconds ); } // Wait the delay time System.Threading.Thread.Sleep(delayTime); } // Go over each BAM agent and send his health report. foreach (string bamAgentUID in _bamUIDs.Keys) { // Create the health string to send WBXXml health = createHealthReport( Constants.AGENT_TYPES.BAM, bamAgentUID, currentVersion, (string)_bamUIDs[bamAgentUID] ); // Reset the stop watch stopWatch.Reset(); stopWatch.Start(); // Send the health report to the agent // configuration manager. string healthResponse = _serviceClient.reportHealth( health.ToString() ); // Stop the stop watch stopWatch.Stop(); totalTimeInMilliseconds = calculateTimeInMilliseconds( stopWatch.Elapsed ); // Update performance counter //counter.RawValue = stopWatch.Elapsed.Seconds; // Check for an error if (healthResponse.IndexOf("error", 0, StringComparison.CurrentCultureIgnoreCase) > -1) { sw.WriteLine( DATA_COLLECTOR_FILE_ERROR_LINE, DateTime.Now.ToString(Constants.TIMESTAMP_FORMAT), bamAgentUID, health.ToString() ); } else { // Write the data to the data collector file sw.WriteLine( DATA_COLLECTOR_FILE_DATA_LINE, DateTime.Now.ToString(Constants.TIMESTAMP_FORMAT), bamAgentUID, totalTimeInMilliseconds ); } // flush sw.Flush(); // Wait the delay time Thread.Sleep(delayTime); } #endregion } // Increment the number of threads finished. Interlocked.Increment(ref _numberOfThreadsFinished); }
private static WBXXml createHealthReport( string agentType, string agentUID, string agentVersion, string agentConfigId ) { WBXXml result = new WBXXml(_baseHealthXML); // Update the agent uid in the xml result.updateFirstNameValue( "uid", agentUID ); // Update the agent type in the xml result.updateFirstNameValue( "type", agentType ); // Update the agent version in the xml result.updateFirstNameValue( "version", agentVersion ); // Update the agent config id in the xml result.updateFirstNameValue( "configid", agentConfigId ); return result; }