Get started with Opsgenie as a user
Learn how to configure your profile, get notifications from Opsgenie and view on-call schedules.
Marid is deprecated and will be permanently retired on November 21st, 2022. Read the community post for more details.
If you never used our extensibility platform before, visit Opsgenie Edge Connector as an extensibility platform to find out how to run it with your Opsgenie account.
If you're using Marid and want to migrate to Opsgenie Edge Connector, visit Why should you migrate to Opsgenie Edge Connector.
OEC does not have proxy server functionality. If you are using Marid's proxy server functionality, you should use other proxy server solutions. For reference, here is the list of common tools that can be used for this purpose: FreeProxy, Squid, Nginx, Wingate, TinyProxy, Ultrasurf, Privoxy, Polipo, Apache Traffic Server...
OEC does not have web server functionality. The following tutorial is a basic demonstration of achieving the same functionality by using DjangoServer. It is a free and open source web framework.
Install Django server:
pip install Django==2.2.5
Create a project to serve your script server:
django-admin startproject oecserver
Create scripts folder under the project that you created at step 2 and add the scripts that you want to execute under this folder. For this example,
hello.py
is added under the scripts folder which prints "Hello World!" to the console.
Create
views.py
under the project folder. views.py contains the following lines of codes:
view.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
from django.views.decorators.csrf import csrf_exempt
from django.http import HttpResponse
import json,requests
from subprocess import Popen, PIPE, STDOUT
def hello():
command = ["python3","oecserver/scripts/hello.py","create" ]
try:
process = Popen(command, stdout=PIPE, stderr=STDOUT)
output = process.stdout.read()
exitstatus = process.poll()
if (exitstatus==0):
return {"status": "Success", "output":str(output)}
else:
return {"status": "Failed", "output":str(output)}
except Exception as e:
return {"status": "failed", "output":str(e)}
@csrf_exempt
def execute(request):
data = hello()
response = HttpResponse(json.dumps(data) , content_type='application/json', status=200)
return response
execute
method is the main method that handles the HTTP requests. It calls
hello
method to execute the script and adds the result of the execution to the HTTP response. You can run any executable or script implemented with other languages with the same approach above.
Manipulate urls.py to bind your script with URLs:
urls.py
1
2
3
4
5
6
7
8
9
10
11
from django.contrib import admin
from django.urls import path
from django.conf.urls import url
from django.contrib import admin
from django.views import generic
from oecserver.views import execute #added
urlpatterns = [
path('admin/', admin.site.urls),
url(r'^hello_api$', execute)
]
hello_api
is the URL you bind and
execute
is name of the main method implemented at
views.py
.
Start your server. You can change the host and port number by manipulating the last parameter of the following command:
python ./manage.py runserver 0.0.0.0:8000
You can execute the command below to test your server:
curl -i -X POST localhost:8000/hello_api -d '{"anyData":"data"}'
response
1
2
3
4
5
6
7
8
HTTP/1.1 200 OK
Date: Mon, 16 Sep 2019 14:20:16 GMT
Server: WSGIServer/0.2 CPython/3.7.0
Content-Type: application/json
X-Frame-Options: SAMEORIGIN
Content-Length: 54
{"status": "Success", "output": "b'Hello, World!\\n'"}
The example above is just a basic starter tutorial for the migration. You can check Django's website for more features and details. By using Django and Python SDK (or any other SDK or script of your choice), the same behavior can be achieved.
Was this helpful?