#!/usr/bin/env bash


URL='http://192.168.11.95/zabbix/api_jsonrpc.php'
HEADER='Content-Type:application/json'

USER='"Admin"'
PASS='"zabbix"'

authentication()
{
    JSON='
    {
        "jsonrpc": "2.0",
        "method": "user.login",
        "params": {
            "user": '$USER',
            "password": '$PASS'
        },
        "id": 0
    }
    '
    curl -s -X POST -H "$HEADER" -d "$JSON" "$URL" | cut -d '"' -f8
}

TOKEN=$(authentication)

createAction()
{
    	JSON='
	{
		"jsonrpc": "2.0",     
		"method": "action.create",     
		"params": 
		{
		"name": "Information", 
		"eventsource": 0, 
		"status": 0, 
		"esc_period": "2m", 
		"filter": {
			"evaltype": 0, 
			"conditions": [
			{
				"conditiontype": 4, 
				"operator": 0, 
				"value": 1
			}
			]
		}, 
		"operations": [
		{
			"operationtype": 0, 
			"esc_period": "1m", 
			"esc_step_from": 1, 
			"esc_step_to": 1, 
			"evaltype": 0, 
			"opmessage_usr": [
			{
				"userid": "2"
			}
			], 
			"opmessage": {
				"default_msg": 1, 
				"mediatypeid": "9",
				"message": "Hi",
				"subject": "test"
			}, 
			"opconditions": [
			{
				"conditiontype": 14,
				"operator": 0, 
				"value": "0"
			}
			]
		}
		]
		},     
	   	"auth": "'$TOKEN'",
           	"id": 1
       	}
     	'
#    echo $JSON
    curl -s -X POST -H "$HEADER" -d "$JSON" "$URL"
}

createAction

