Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use microseconds in addition to PID. Use the sorted file list. #4

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 4 additions & 3 deletions pagerduty.py
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,7 @@ def file_timestamp(file_name):
return int(re.search('pd_(\d+)_', file_name).group(1))

sorted_file_names = sorted(pd_file_names, key=file_timestamp)
return pd_file_names
return sorted_file_names
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

:P


def _flush_queue(self):
file_names = self._queued_files()
Expand Down Expand Up @@ -173,8 +173,8 @@ def lock_and_flush_queue(self):
def enqueue(self, event):
encoded_event = json.dumps(event)
process_id = os.getpid()
time_seconds = int(time.time())
file_name = "%s/pd_%d_%d" % (self.queue_dir, time_seconds, process_id)
time_microseconds = int(time.time() * 1000000)
file_name = "%s/pd_%d_%d" % (self.queue_dir, time_microseconds, process_id)
logger.info("Queuing event %s" % str(event))
with open(file_name, "w", 0600) as f:
f.write(encoded_event)
Expand Down Expand Up @@ -243,3 +243,4 @@ def event(self):
if len(sys.argv) == 4:
pagerduty_queue.enqueue(Zabbix(sys.argv).event())
pagerduty_queue.lock_and_flush_queue()