Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP

Loading…

pagerduty worker example: python implementation #27

Merged
merged 2 commits into from

2 participants

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
This page is out of date. Refresh to see the latest.
Showing with 43 additions and 0 deletions.
  1. +19 −0 python/PagerDuty.py
  2. +24 −0 python/pagerduty/worker.py
View
19 python/PagerDuty.py
@@ -0,0 +1,19 @@
+from ironworker import *
+
+import pagerduty
+import os
+import shutil
+
+#here we have to include pagerduty library with worker.
+worker_dir = os.path.dirname(__file__) + '/pagerduty'
+pd_dir = os.path.dirname(pagerduty.__file__)
+shutil.copytree(pd_dir, worker_dir + '/pagerduty') #copy it to worker directory
+
+payload = {'pagerduty': {'service_key': PAGERDUTY_SERVICE_KEY}}
+
+worker = IronWorker(config='config.ini')
+IronWorker.zipDirectory(directory=worker_dir, destination='pagerduty-py.zip', overwrite=True)
+
+res = worker.postCode(runFilename='pagerduty.py', zipFilename='pagerduty-py.zip', name='pagerduty-py')
+
+task = worker.postTask(name='pagerduty-py', payload=payload)
View
24 python/pagerduty/worker.py
@@ -0,0 +1,24 @@
+import argparse
+import json
+from pagerduty import PagerDuty
+
+parser = argparse.ArgumentParser(
+ description="Calculates the Fibonacci sequence up to a maximum number")
+parser.add_argument("-payload", type=str, required=False,
+ help="The location of a file containing a JSON payload.")
+args = parser.parse_args()
+
+pd = False
+if args.payload is not None:
+ payload = json.loads(open(args.payload).read())
+ if 'pagerduty' in payload:
+ pd = PagerDuty(payload['pagerduty']['secret_key'])
+
+def trigger_alert(description):
+ if pd:
+ pd.trigger(description)
+
+#some code here
+
+#let's report an incident eventually
+trigger_alert('Something bad happened, evacuate immediately')
Something went wrong with that request. Please try again.