Fix parsing xml event

This commit is contained in:
Yue Zhang
2016-01-21 13:05:13 +08:00
parent d36ee00f55
commit 79f6dcebb8
4 changed files with 38 additions and 5 deletions
+3 -3
View File
@@ -66,6 +66,7 @@ def parse_xml_event(data_str):
param_nodes = findall(xml_doc, 'Param')
for param_node in param_nodes:
event.parameters.append(parse_xml_param(param_node))
return event
except Exception as e:
raise ValueError(ustr(e))
@@ -153,8 +154,7 @@ class MonitorHandler(object):
event.parameters.extend(self.sysinfo)
event_list.events.append(event)
except (ValueError, ProtocolError) as e:
logger.info("Failed to decode event file: {0}", e)
logger.info(data_str)
logger.warn("Failed to decode event file: {0}", e)
continue
if len(event_list.events) == 0:
@@ -178,5 +178,5 @@ class MonitorHandler(object):
try:
self.collect_and_send_events()
except Exception as e:
logger.verb("Failed to send events: {0}", e)
logger.warn("Failed to send events: {0}", e)
time.sleep(60)
+2 -2
View File
@@ -609,13 +609,13 @@ class DefaultOSUtil(object):
raise OSUtilError("Failed to get procerssor cores")
def set_admin_access_to_ip(self, dest_ip):
#This root allow root to access dest_ip
#This allows root to access dest_ip
rm_old= "iptables -D OUTPUT -d {0} -j ACCEPT -m owner --uid-owner 0"
rule = "iptables -A OUTPUT -d {0} -j ACCEPT -m owner --uid-owner 0"
shellutil.run(rm_old.format(dest_ip), chk_err=False)
shellutil.run(rule.format(dest_ip))
#This root blocks all users to access dest_ip
#This blocks all other users to access dest_ip
rm_old = "iptables -D OUTPUT -d {0} -j DROP"
rule = "iptables -A OUTPUT -d {0} -j DROP"
shellutil.run(rm_old.format(dest_ip), chk_err=False)
+1
View File
@@ -0,0 +1 @@
<Data><Provider id="69B669B9-4AF8-4C50-BDC4-6006FA76E975"/><Event id="1"/><Param Name="OperationSuccess" Value="True" T="mt:bool" /><Param Name="Processors" Value="0" T="mt:uint64" /><Param Name="OpcodeName" Value="" T="mt:wstr" /><Param Name="Version" Value="1.4.1.0" T="mt:wstr" /><Param Name="RoleName" Value="" T="mt:wstr" /><Param Name="IsInternal" Value="False" T="mt:bool" /><Param Name="RAM" Value="0" T="mt:uint64" /><Param Name="ExecutionMode" Value="IAAS" T="mt:wstr" /><Param Name="RoleInstanceName" Value="" T="mt:wstr" /><Param Name="Name" Value="CustomScript" T="mt:wstr" /><Param Name="Message" Value="(01302)Script is finished.&#10;---stdout---&#10;hello&#10;&#10;---errout---&#10;&#10;" T="mt:wstr" /><Param Name="KeywordName" Value="" T="mt:wstr" /><Param Name="TaskName" Value="" T="mt:wstr" /><Param Name="OSVersion" Value="" T="mt:wstr" /><Param Name="Operation" Value="RunScript" T="mt:wstr" /><Param Name="ContainerId" Value="" T="mt:wstr" /><Param Name="GAVersion" Value="" T="mt:wstr" /><Param Name="TenantName" Value="" T="mt:wstr" /><Param Name="Duration" Value="0" T="mt:uint64" /><Param Name="ExtensionType" Value="" T="mt:wstr" /></Data>
+32
View File
@@ -0,0 +1,32 @@
# Copyright 2014 Microsoft Corporation
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#
# Requires Python 2.4+ and Openssl 1.0+
#
# Implements parts of RFC 2131, 1541, 1497 and
# http://msdn.microsoft.com/en-us/library/cc227282%28PROT.10%29.aspx
# http://msdn.microsoft.com/en-us/library/cc227259%28PROT.13%29.aspx
from tests.tools import *
from azurelinuxagent.exception import *
from azurelinuxagent.distro.default.monitor import *
class TestMonitor(AgentTestCase):
def test_parse_xml_event(self):
data_str = load_data('ext/event.xml')
event = parse_xml_event(data_str)
self.assertNotEquals(None, event)
self.assertNotEquals(0, event.parameters)
self.assertNotEquals(None, event.parameters[0])