Zmsoap: Difference between revisions

No edit summary
Line 185: Line 185:


==Related==
==Related==
[[zmmailbox]] is a much refined command & is the typical admin tool along with [[zmprov]]
[[zmmailbox]] uses refined syntax & is the typical admin tool along with [[zmprov]]




[[Category:Command Line Interface]]
[[Category:Command Line Interface]]

Revision as of 18:00, 17 December 2008

Intro

Specify the request on the command line in an XPath-inspired syntax, and zmsoap takes care of authenticating, generating the envelope, sending the request, and writing the response to stdout.

(zmjava com.zimbra.common.soap.SoapCommandUtil got revamped as zmsoap in 5.0.7)

Usage

                                                
$ zmsoap --help
Usage:                                                                          
zmsoap [options] <path1> [<path2> ...]                                          
options                                                                         
  --help (-h)                 Print usage information.                          
  --mailbox (-m) name         Mailbox account name.  mail and account requests  
                              are sent to this account.  Also used for          
                              authentication if -a and -z are not specified.    
  --target name               Target account name to which requests will be     
                              sent.  Only used for non-admin sessions.          
  --admin (-a) name           Admin account name to authenticaste as.           
  --zadmin (-z)               Authenticate with zimbra admin name/password from 
                              localconfig.                                      
  --password (-p) pass        Password.                                         
  --passfile (-P) path        Read password from file.                          
  --element (-e) path         Root element path.  If specified, all path        
                              arguments that don't start with a slash (/) are   
                              relative to this element.                         
  --type (-t) type            SOAP request type (mail, account, admin).         
                              Default is admin.                                 
  --url (-u) http[s]://...    Server hostname and optional port.                
  --verbose (-v)              Print the SOAP request and other status           
                              information.                                      
  path [path ...]             Element or attribute path and value.  Roughly     
                              follows XPath syntax:                             
                              [/]element1[/element2][/@attr][=value].         

Examples

GetAccountInfo

$ zmsoap -z -e GetAccountInfoRequest/account=user1 -v @by=name

Sending admin auth request to https://localhost:7071/service/admin/soap

<GetAccountInfoRequest xmlns="urn:zimbraAdmin">
  <account by="name">user1</account>
</GetAccountInfoRequest>

<GetAccountInfoResponse xmlns="urn:zimbraAdmin">
  <name>user1@cosmonaut.zimbra.com</name>
  <a n="zimbraId">decf3d72-623c-44d1-be34-23df4d285fb1</a>
  <a n="zimbraMailHost">cosmonaut.zimbra.com</a>
  <soapURL>http://server.zimbra.com:7070/service/soap/</soapURL>
  <adminSoapURL>https://server.zimbra.com:7071/service/admin/soap/</adminSoapURL>
</GetAccountInfoResponse>


$ zmsoap -m user1 -p test123 -u http://localhost:7070/service/soap --type account GetInfoRequest | head

<GetInfoResponse xmlns="urn:zimbraAccount">
  <version>unknown unknown unknown unknown</version>
  <id>decf3d72-623c-44d1-be34-23df4d285fb1</id>
  <name>user1@server.zimbra.com</name>
  <crumb>dace2c2c21df2009dc657b8f9e94b1cc</crumb>
  <lifetime>172799977</lifetime>
  <rest>http://server.zimbra.com:7070/home/user1</rest>
  <used>10775433</used>
  <prevSession>1211496468000</prevSession>

Search

$ zmsoap -z -m user1 SearchRequest/query=in:inbox | head

<SearchResponse xmlns="urn:zimbraMail" offset="0" more="1" sortBy="dateDesc">
  <c f="u" score="1.0" id="-514" n="1" sf="1211495060000" d="1211495060000">
    <su>Goodmail test</su>
    <fr>Tastes great!</fr>
    <e d="goodmailbot42" a="goodmailbot42@aol.com" t="f"></e>
    <m id="514"></m>
  </c>
  <c n="1" score="1.0" d="1211495060000" id="-525" f="u" sf="1211495060000">
    <su>Welcome to the Zimbra Collaboration Suite source!</su>

EmptyFolder

$ zmsoap -z -m user@domain.com -v -e FolderActionRequest/action op=empty id=1 recursive=false

Sending admin auth request to https://localhost:7071/service/admin/soap

<FolderActionRequest xmlns="urn:zimbraMail">
  <action>
    <op>empty</op>
    <id>1</id>
    <recursive>false</recursive>
  </action>
</FolderActionRequest>

<FolderActionResponse xmlns="urn:zimbraMail">
  <action op="empty" id="1"></action>
</FolderActionResponse>

Connectivity To Another Server

This command sends a GetServerRequest to mailbox1.domain.com and filters enabled services with grep.

$ zmsoap -z -v -u https://mailbox1.domain.com:7071/service/admin/soap/ -e GetServerRequest/server=mailbox2.domain.com @by=name | grep zimbraServiceEnabled
    <a n="zimbraServiceEnabled">antivirus</a>
    <a n="zimbraServiceEnabled">antispam</a>
    <a n="zimbraServiceEnabled">logger</a>
    <a n="zimbraServiceEnabled">mailbox</a>
    <a n="zimbraServiceEnabled">mta</a>
    <a n="zimbraServiceEnabled">stats</a>
    <a n="zimbraServiceEnabled">snmp</a>
    <a n="zimbraServiceEnabled">ldap</a>
    <a n="zimbraServiceEnabled">spell</a>
    <a n="zimbraServiceEnabled">imapproxy</a>

Active Server Sessions With DumpSessionsRequest

Dump login sessions from one server
$ zmsoap -z -t admin -v DumpSessionsRequest
Sending admin auth request to https://localhost:7071/service/admin/soap

<DumpSessionsRequest xmlns="urn:zimbraAdmin"/>

<DumpSessionsResponse xmlns="urn:zimbraAdmin" activeSessions="7">
  <imap activeSessions="2" activeAccounts="2"></imap>
  <admin activeAccounts="1" activeSessions="5"></admin>
</DumpSessionsResponse>
Dump login sessions by account
$ zmsoap -z -t admin -v -e DumpSessionsRequest @groupByAccount=1 @listSessions=1
Sending admin auth request to https://localhost:7071/service/admin/soap

<DumpSessionsRequest xmlns="urn:zimbraAdmin" groupByAccount="1" listSessions="1"/>

<DumpSessionsResponse xmlns="urn:zimbraAdmin" activeSessions="7">
  <imap activeSessions="2" activeAccounts="2">
    <zid id="cb3136ab-ba07-447e-beeb-82b2b8072d62" name="user1@domain.com">
      <s cd="1229081559845" sid="22780" ld="1229110373411">
        <imap dirty="0" folder="INBOX" size="17" writable="1"></imap>
      </s>
    </zid>
    <zid name="user2@domain.com" id="8acfc531-330b-49a3-b722-a0ef06f4f6c7">
      <s sid="22782" ld="1229110667123" cd="1229085464155">
        <imap dirty="0" writable="1" size="6352" folder="INBOX"></imap>
      </s>
    </zid>
  </imap>
  <admin activeAccounts="1" activeSessions="5">
    <zid name="zimbra" id="e0fafd89-1360-11d9-8661-000a95d98ef2">
      <s ld="1229110825059" cd="1229110825059" sid="32914"></s>
      <s ld="1229110854718" sid="32915" cd="1229110854718"></s>
      <s cd="1229110854745" sid="32916" ld="1229110854745"></s>
      <s cd="1229110876252" sid="32917" ld="1229110876252"></s>
      <s cd="1229110876279" sid="32918" ld="1229110876279"></s>
    </zid>
  </admin>
</DumpSessionsResponse>
Dump login sessions from ServerA and ServerB simultaneously
$ echo -e "\nServer A $(date)"; zmsoap -z -t admin DumpSessionsRequest && \
> echo -e "\nServer B $(date)"; zmsoap -z -a admin@zmb.moc -p zimbra -t admin -u https://ubu08.zmb.moc:7071/service/admin/soap/ DumpSessionsRequest

Server A Fri Dec 12 15:02:04 EST 2008

<DumpSessionsResponse xmlns="urn:zimbraAdmin" activeSessions="7">
  <imap activeAccounts="2" activeSessions="2"></imap>
  <admin activeSessions="5" activeAccounts="1"></admin>
</DumpSessionsResponse>

Server B Fri Dec 12 15:02:06 EST 2008

<DumpSessionsResponse xmlns="urn:zimbraAdmin" activeSessions="6">
  <soap activeSessions="1" activeAccounts="1"></soap>
  <admin activeAccounts="1" activeSessions="5"></admin>
</DumpSessionsResponse>

Related

zmmailbox uses refined syntax & is the typical admin tool along with zmprov

Jump to: navigation, search