diff options
author | Ćukasz 'sil2100' Zemczak <lukasz.zemczak@ubuntu.com> | 2017-03-15 10:19:34 +0100 |
---|---|---|
committer | usd-importer <ubuntu-server@lists.ubuntu.com> | 2017-03-17 13:08:24 +0000 |
commit | 83be006e288c58a46f5b76c29b6886c1f417d88c (patch) | |
tree | 91ba57e843714c232b5af5ab8dc6f3322ff7841e /azurelinuxagent/common/event.py | |
parent | d064ab0bffd429382ea4fafeb144784d403848bd (diff) | |
download | vyos-walinuxagent-83be006e288c58a46f5b76c29b6886c1f417d88c.tar.gz vyos-walinuxagent-83be006e288c58a46f5b76c29b6886c1f417d88c.zip |
Import patches-unapplied version 2.2.6-0ubuntu1 to ubuntu/zesty-proposed
Imported using git-ubuntu import.
Changelog parent: d064ab0bffd429382ea4fafeb144784d403848bd
New changelog entries:
* New upstream release (LP: #1661750).
* debian/control:
- Change the maintainer to Ubuntu Developers (LP: #1657528).
- Add the dependency of isc-dhcp-client as our maintainer scripts assume
it's installed.
- Add trailing commas to dependencies, add whitespaces.
* Rename ephemeral-disk-warning.sh to ephemeral-disk-warning (lintian error).
* debian/docs:
- Remove LICENSE.txt as it's redundant.
* debian/postinst:
- Stop checking for update-initramfs existence using the absolute path, use
the 'command' command instead to make lintian happy.
* Remove debian/patches/disable-auto-update.patch:
- We now ship with auto-updates enabled (LP: #1650522).
* debian/maintscript:
- Add a maintscript to rename the old logrotate file on upgrade from an
ancient version of walinuxagent (LP: #1673152).
Diffstat (limited to 'azurelinuxagent/common/event.py')
-rw-r--r-- | azurelinuxagent/common/event.py | 39 |
1 files changed, 24 insertions, 15 deletions
diff --git a/azurelinuxagent/common/event.py b/azurelinuxagent/common/event.py index 4037622..9265820 100644 --- a/azurelinuxagent/common/event.py +++ b/azurelinuxagent/common/event.py @@ -28,29 +28,31 @@ import azurelinuxagent.common.logger as logger from azurelinuxagent.common.exception import EventError, ProtocolError from azurelinuxagent.common.future import ustr from azurelinuxagent.common.protocol.restapi import TelemetryEventParam, \ - TelemetryEventList, \ - TelemetryEvent, \ - set_properties, get_properties + TelemetryEventList, \ + TelemetryEvent, \ + set_properties, get_properties from azurelinuxagent.common.version import DISTRO_NAME, DISTRO_VERSION, \ - DISTRO_CODE_NAME, AGENT_VERSION, \ - CURRENT_AGENT, CURRENT_VERSION + DISTRO_CODE_NAME, AGENT_VERSION, \ + CURRENT_AGENT, CURRENT_VERSION class WALAEventOperation: - ActivateResourceDisk="ActivateResourceDisk" + ActivateResourceDisk = "ActivateResourceDisk" Disable = "Disable" Download = "Download" Enable = "Enable" HealthCheck = "HealthCheck" - HeartBeat="HeartBeat" + HeartBeat = "HeartBeat" Install = "Install" + InitializeHostPlugin = "InitializeHostPlugin" Provision = "Provision" - Restart="Restart" - UnhandledError="UnhandledError" + Restart = "Restart" + UnhandledError = "UnhandledError" UnInstall = "UnInstall" Upgrade = "Upgrade" Update = "Update" + class EventLogger(object): def __init__(self): self.event_dir = None @@ -66,22 +68,24 @@ class EventLogger(object): if len(os.listdir(self.event_dir)) > 1000: raise EventError("Too many files under: {0}".format(self.event_dir)) - filename = os.path.join(self.event_dir, ustr(int(time.time()*1000000))) + filename = os.path.join(self.event_dir, + ustr(int(time.time() * 1000000))) try: - with open(filename+".tmp",'wb+') as hfile: + with open(filename + ".tmp", 'wb+') as hfile: hfile.write(data.encode("utf-8")) - os.rename(filename+".tmp", filename+".tld") + os.rename(filename + ".tmp", filename + ".tld") except IOError as e: raise EventError("Failed to write events to file:{0}", e) - def add_event(self, name, op="", is_success=True, duration=0, version=CURRENT_VERSION, + def add_event(self, name, op="", is_success=True, duration=0, + version=CURRENT_VERSION, message="", evt_type="", is_internal=False): event = TelemetryEvent(1, "69B669B9-4AF8-4C50-BDC4-6006FA76E975") event.parameters.append(TelemetryEventParam('Name', name)) event.parameters.append(TelemetryEventParam('Version', str(version))) event.parameters.append(TelemetryEventParam('IsInternal', is_internal)) event.parameters.append(TelemetryEventParam('Operation', op)) - event.parameters.append(TelemetryEventParam('OperationSuccess', + event.parameters.append(TelemetryEventParam('OperationSuccess', is_success)) event.parameters.append(TelemetryEventParam('Message', message)) event.parameters.append(TelemetryEventParam('Duration', duration)) @@ -93,8 +97,10 @@ class EventLogger(object): except EventError as e: logger.error("{0}", e) + __event_logger__ = EventLogger() + def add_event(name, op="", is_success=True, duration=0, version=CURRENT_VERSION, message="", evt_type="", is_internal=False, reporter=__event_logger__): @@ -108,9 +114,11 @@ def add_event(name, op="", is_success=True, duration=0, version=CURRENT_VERSION, version=str(version), message=message, evt_type=evt_type, is_internal=is_internal) + def init_event_logger(event_dir, reporter=__event_logger__): reporter.event_dir = event_dir + def dump_unhandled_err(name): if hasattr(sys, 'last_type') and hasattr(sys, 'last_value') and \ hasattr(sys, 'last_traceback'): @@ -119,9 +127,10 @@ def dump_unhandled_err(name): last_traceback = getattr(sys, 'last_traceback') error = traceback.format_exception(last_type, last_value, last_traceback) - message= "".join(error) + message = "".join(error) add_event(name, is_success=False, message=message, op=WALAEventOperation.UnhandledError) + def enable_unhandled_err_dump(name): atexit.register(dump_unhandled_err, name) |