Template:DoveadmHTTPapi: Difference between revisions

From Open-Xchange
No edit summary
No edit summary
Line 702: Line 702:
  </nowiki>
  </nowiki>


== doveadm director
== doveadm director ==
=== dove adm director status ===
=== doveadm director status ===
   
   
Show backend statuses on directors. Available only in directors
Show backend statuses on directors. Available only in directors
Line 750: Line 750:
|tag
|tag
|String
|String
|Show director status for Tagged host
|Show director status for Tagged hosts only
|NewBackend
|NewBackend
|}
|}
example:
<nowiki>
[
    [
        "directorStatus",
        {},
        "bb"
    ]
]
# curl -X POST -u doveadm:hellodoveadm -H "Content-Type: application/json" -d '[["directorStatus",{},"bb"]]' http://localhost:8080/doveadm/v1
</nowiki>
response
<nowiki>
[
    [
        "doveadmResponse",
        [
            {
                "mail server ip": "10.0.0.234",
                "state": "up",
                "state-changed": "2016-12-15 08:31:37",
                "tag": "",
                "users": "1",
                "vhosts": "100"
            },
            {
                "mail server ip": "10.0.0.235",
                "state": "up",
                "state-changed": "2016-12-15 08:31:04",
                "tag": "",
                "users": "0",
                "vhosts": "100"
            }
        ],
        "bb"
    ]
]
CLI: doveadm director status
</nowiki>
=== doveadm director map ===
list current user → host mappings. Applicable to director only
<nowiki>
    "command": "directorMap",
    "parameters": [
        {
            "name": "socketPath",
            "type": "string"
        },
        {
            "name": "usersFile",
            "type": "string"
        },
        {
            "name": "hashMap",
            "type": "boolean"
        },
        {
            "name": "userMap",
            "type": "boolean"
        },
        {
            "name": "host",
            "type": "string"
        }
    ]
}
</nowiki>
parameters
{| class="wikitable"
|-
!style="font-weight: bold" |Parameter
!style="font-weight: bold" |Type
!style="font-weight: bold" |Description
!style="font-weight: bold" |example
|-
|socketPath
|String
|Path to doveadm socket
|/var/run/dovecot/doveadm-server
|-
|usersFile
|String
|provide Path to users list. One username per line
|/etc/dovecot/userlist.txt
|-
|hashMap
|Boolean
|Output users as hashmap
|true
|-
|host
|String
|Show only mappings to given host
|10.0.0.234

Revision as of 11:50, 28 February 2017

doveadm http api

configuration

To be able to use doveadm http api it’s mandatory to configure either password for doveadm or a api key.

To configure password for doveadm service in /etc/dovecot/dovecot.conf:

doveadm_password = hellodoveadm

Or if preferred to use separate key for doveadm http api then it can be enabled by defining key in config:

doveadm_api_key = key

And to enable the doveadm http listener:

 service doveadm {
  unix_listener doveadm-server {
    user = vmail
  }
  inet_listener {
   port = 2425
  }
  inet_listener http {
    port = 8080
    #ssl = yes # uncomment to enable https
  }
} 
 

usage

connecting to endpoint can then be done by using standard http protocol and authentication headers. To get list the commands supported by the endpoint, the following example commands can be used:

X-Dovecot-API auth usage:

curl -H "Authorization: X-Dovecot-API <base64 dovecot_api_key>" http://host:port/doveadm/v1

Basic auth usage:

curl -H "Authorization: Basic <base64 doveadm:doveadm_password>" http://host:port/doveadm/v1

or by letting curl to form the base64 encoded authentication basig authentication header:

curl –u doveadm:password http://host:port/doveadm/v1

command usage

All commands sent to the API needs to be posted in json format using “Content-Type: application/json” in headers for the request type and the json content as payload in format:


[
    [
        "command1",
        {
            "parameter1": "value",
            "parameter2": "value",
            "parameter3": "value"
        },
        "identifier"
    ]
]
 

Multiple commands can be submitted in one json payload:

[
    [
        "command1",
        {
            "parameter1": "value",
            "parameter2": "value"
        },
        "identifier1"
    ],
    [
        "command2",
        {
            "parameter1": "value",
            "parameter2": "value"
        },
        "identifier2"
    ]
]
 

For now it is safest not to send multiple commands in one json payload, as some commands may kill the server in certain error conditions and leaving you without any response. Also it is not guaranteed that the commands will be processed in order.

All commands are case sensitive.

example usage

In the example we ask dovecot to reload configuration:


son payload:

[
    [
        "reload",
        {},
        "a2"
    ]
]

 

submitting the command with curl:

  1. curl -v -u doveadm:hellodoveadm -X POST http://localhost:8080/doveadm/v1 -H "Content-Type: application/json" -d '[["reload",{},"a2"]]'

command line equivalent

doveadm reload


successful response


[
    [
        "doveadmResponse",
        [],
        "a2"
    ]
]
 

failure response


[
    [
        "error",
        {
            "exitCode": 68,
            "type": "exitCode"
        },
        "a2"
    ]
 

failure codes

2 Success but mailbox changed during operation
64 Invalid parameters
65 Data error
67 User does not exist
68 User does not have session
73 User out of quota
75 Temporary error
77 No permission
78 valid configuration

Supported commands

doveadm service

doveadm service stop

stop one or more dovecot services on target host

{
    "command": "serviceStop",
    "parameters": [
        {
            "name": "service",
            "type": "array"
        }
    ]
}
 

parameters:

Parameter Type Description example
service string array Name of service to stop [“imap”,”imap-hibernate”]

example:

[
    [
        "serviceStop",
        {
            "service": [
                "imap",
                "imap-hibernate"
            ]
        },
        "aa"
    ]
]

# curl -X POST -u doveadm:hellodoveadm -H "Content-Type: application/json" -d '[["serviceStop",{"service":["imap","imap-hibernate"]},"aa"]]' http://localhost:8080/doveadm/v1

CLI: doveadm service stop imap imap-hibernate
 

doveadm stop

stop dovecot on the target host


{
    "command": "stop",
    "parameters": []
}


no parameters
 

example:

[
    [
        "stop",
        {},
        "a1"
    ]
]

# curl -u doveadm:hellodoveadm -X POST http://localhost:8080/doveadm/v1 -H "Content-Type: application/json" -d '[["stop",{},"a1"]]'

CLI: doveadm stop
 

doveadm reload

reload dovecot configuration

{
    "command": "reload",
    "parameters": []
}
 

example:

[
    [
        "reload",
        {},
        "a2"
    ]
]

# curl -X POST -u doveadm:hellodoveadm -H "Content-Type: application/json" -d '[["reload",{},"aa"]]' http://localhost:8080/doveadm/v1

CLI: doveadm reload
 

doveadm stats

doveadm stats dump

dovecot collected dovecot statistics

  {
     "command": "statsDump",
     "parameters": [
         {
             "name": "socketPath",
             "type": "string"
         },
         {
             "name": "type",
             "type": "string"
         },
         {
             "name": "filter",
             "type": "string"
         }
     ]
 }
 
parameters
Parameter Type Description example
socketPath string Path to doveadm socket /var/run/dovecot/dovearm-server
type string String Type of stats to dump global
filter String Dump filter last update 1483101542

Example:

[
    [
        "statsDump",
        {
            "type": "global"
        },
        "aa"
    ]
]

# curl -X POST -u doveadm:hellodoveadm -H "Content-Type: application/json" -d '[["statsDump",{"type":"global"},"aa"]]' http://localhost:8080/doveadm/v1
 

response:

[
    [
        "doveadmResponse",
        [
            {
                "auth_cache_hits": "0",
                "auth_cache_misses": "0",
                "auth_db_tempfails": "0",
                "auth_failures": "0",
                "auth_master_successes": "0",
                "auth_successes": "0",
                "clock_time": "0.0",
                "disk_input": "0",
                "disk_output": "0",
                "fscache_read": "0",
                "fscache_stat": "0",
                "fscache_write": "0",
                "idx_del": "0",
                "idx_iter": "0",
                "idx_read": "0",
                "idx_read_usecs": "0",
                "idx_wbytes": "0",
                "idx_write": "0",
                "idx_write_usecs": "0",
                "invol_cs": "0",
                "last_update": "0.000000",
                "mail_cache_hits": "0",
                "mail_lookup_attr": "0",
                "mail_lookup_path": "0",
                "mail_read_bytes": "0",
                "mail_read_count": "0",
                "maj_faults": "0",
                "min_faults": "0",
                "num_cmds": "0",
                "num_connected_sessions": "0",
                "num_logins": "0",
                "obox_copy": "0",
                "obox_del": "0",
                "obox_iter": "0",
                "obox_read": "0",
                "obox_read_usecs": "0",
                "obox_stat": "0",
                "obox_wbytes": "0",
                "obox_write": "0",
                "obox_write_usecs": "0",
                "read_bytes": "0",
                "read_count": "0",
                "reset_timestamp": "1483104199",
                "sys_cpu": "0.0",
                "user_cpu": "0.0",
                "vol_cs": "0",
                "write_bytes": "0",
                "write_count": "0"
            }
        ],
        "aa"
    ]
]

CLI: doveadm stats dump global
 

doveadm stats reset

reset dovecot statistics

{
    "command": "statsReset",
    "parameters": [
        {
            "name": "socketPath",
            "type": "string"
        }
    ]
}
 

parameters

Parameter Type Description example
socketPath String Path to doveadm socket /var/run/dovecot/doveadm-server

example:

[
    [
        "statsReset",
        {},
        "aa"
    ]
]

curl -v -u doveadm:hellodoveadm -X POST http://localhost:8080/doveadm/v1 -H "Content-Type: application/json" -d '[["statsReset",{},"aa"]]' http://localhost:8080/doveadm/v1

CLI: doveadm stats reset
 

doveadm penalty

show current penalties

{
    "command": "penalty",
    "parameters": [
        {
            "name": "socketPath",
            "type": "string"
        },
        {
            "name": "netmask",
            "type": "string"
        }
    ]
}
 
Parameter Type Description example
socketPath string Path to doveadm socket /var/run/dovecot-server
netmask string To reduce/filter the output supply an IP address or a network range in CIDR notation (ip/mask) 10.0.0.0/24

example:

[
    [
        "penalty",
        {},
        "aa"
    ]
]

# curl -X POST -u doveadm:hellodoveadm -H "Content-Type: application/json" -d '[["penalty",{},"aa"]]' http://localhost:8080/doveadm/v1

CLI: doveadm penalty
 

doveadm kick

Kick user from dovecot. Applicable to session in dovecot backend only

{    
    "command": "kick",
    "parameters": [
        {
            "name": "socketPath",
            "type": "string"
        },
        {
            "name": "force",
            "type": "boolean"
        },
        {
            "name": "mask",
            "type": "array"
        }
    ]
}
 

parameters:

Parameter Type Description example
socketPath string Path to doveadm socket /var/run/roveam-server
force Boolean Do a forced kick? 0
mask string Uid mask testuser001

example:

 [
    [
        "kick",
        {
            "force": 0,
            "mask": "testuser001"
        },
        "aa"
    ]
]

# curl -v -u doveadm:hellodoveadm –H “Content-Type: application/json" -d '[["kick", {"mask":"testuser001"}, "aa"]]' http://localhost:8080/doveadm/v1

CLI: doveadm kick testuser001

response for succesfull kick:

[
    [
        "doveadmResponse",
        [
            {
                "result": "testuser001"
            }
        ],
        "aa"
    ]
]

response in case kick failed:

[
    [
        "error",
        {
            "exitCode": 68,
            "type": "exitCode"
        },
        "aa"
    ]
]
 

doveadm who

list active dovecot sessions


{
    "command": "who",
    "parameters": [
        {
            "name": "socketPath",
            "type": "string"
        },
        {
            "name": "separateConnections",
            "type": "boolean"
        },
        {
            "name": "mask",
            "type": "array"
        }
    ]
}
 

parameters

Parameter Type Description example
socketPath string Path to doveadm socket /var/run/dovecot/doveadm-server
separateConnections Boolean Show each user connection in separate entries 0
mask string array Uid mask testuser001

Example:

[
    [
        "who",
        {
            "mask": "",
            "separateConnections": 0,
            "socketPath": ""
        },
        "aa"
    ]
]

# curl -v -u doveadm:hellodoveadm -X POST http://localhost:ype: application/json" -d '[["who", {}, "aa"]]' http://localhost:8080/doveadm/v1

CLI: doveadm who
 

response:

[
    [
        "doveadmResponse",
        [
            {
                "connections": "1",
                "ips": "(127.0.0.1)",
                "pids": "(4999)",
                "service": "imap",
                "username": "testuser001"
            }
        ],
        "aa"
    ]
]
 

doveadm director

doveadm director status

Show backend statuses on directors. Available only in directors

[
    {
        "command": "directorStatus",
        "parameters": [
            {
                "name": "socketPath",
                "type": "string"
            },
            {
                "name": "user",
                "type": "string"
            },
            {
                "name": "tag",
                "type": "string"
            }
        ]
    }
]
 

parameters:

Parameter Type Description example
socketPath String Path to doveadm socket /var/run/dovecot/doveadm-server
user String Show hashed status for individual user testuser001
tag String Show director status for Tagged hosts only NewBackend

example:

[
    [
        "directorStatus",
        {},
        "bb"
    ]
]

# curl -X POST -u doveadm:hellodoveadm -H "Content-Type: application/json" -d '[["directorStatus",{},"bb"]]' http://localhost:8080/doveadm/v1

 

response

[
    [
        "doveadmResponse",
        [
            {
                "mail server ip": "10.0.0.234",
                "state": "up",
                "state-changed": "2016-12-15 08:31:37",
                "tag": "",
                "users": "1",
                "vhosts": "100"
            },
            {
                "mail server ip": "10.0.0.235",
                "state": "up",
                "state-changed": "2016-12-15 08:31:04",
                "tag": "",
                "users": "0",
                "vhosts": "100"
            }
        ],
        "bb"
    ]
]

CLI: doveadm director status
 

doveadm director map

list current user → host mappings. Applicable to director only


    "command": "directorMap",
    "parameters": [
        {	
            "name": "socketPath",
            "type": "string"
        },
        {
            "name": "usersFile",
            "type": "string"
        },
        {
            "name": "hashMap",
            "type": "boolean"
        },
        {
            "name": "userMap",
            "type": "boolean"
        },
        {
            "name": "host",
            "type": "string"
        }
    ]
}
 

parameters

Parameter Type Description example
socketPath String Path to doveadm socket /var/run/dovecot/doveadm-server
usersFile String provide Path to users list. One username per line /etc/dovecot/userlist.txt
hashMap Boolean Output users as hashmap true
host String Show only mappings to given host 10.0.0.234