Output Formats

Output Formats

For ease of integration with other scripts and utilities, the management utility supports a number of output modes to control how data generated by the management utility is returned.

The following output modes are available:

Text Mode

Selected using --outputmode=text, this mode generates output as formatted, human-readable text. This is the default output mode if no --outputmode parameter is used.

Example output from ccmanage version --outputmode=text:

web:
|  version: "3.0.0"
|  accounts: "81"
|  other:
|  |  Load (1m):
|  |  |  0: "f"
|  |  |  1: "0.2"
Result: OK Centova Cast v3.0.0

BASH script

Selected using --outputmode=bash, this mode generates output as a series of variable assignments suitable for use in BASH scripts.

Example output from ccmanage version --outputmode=bash:

WEB_VERSION="3.0.0"
WEB_ACCOUNTS="81"
WEB_OTHER_LOAD1M_0="f"
WEB_OTHER_LOAD1M_1="0.18"
SUCCESSFUL="1"
MESSAGE="Centova Cast v3.0.0"

Example implementation in a BASH script:

##!/bin/sh
eval $(/usr/local/centovacast/sbin/sumanage version --outputmode=bash)
[ "$SUCCESSFUL" -eq 0 ] && echo "Error: $MESSAGE" && exit 1
echo "Centova Cast version is $WEB_VERSION"

PHP Serialized

Selected using --outputmode=serialize, this mode enerates output as a PHP serialized string, usable via PHP's unserialize() function.

Example output from ccmanage version --outputmode=serialize:

a:3:{s:10:"successful";i:1;s:7:"message";s:21:"Centova Cast v3.0.0";s:4:"data";a:1:{s:3:"web";
    a:3:{s:7:"version";s:7:"3.0.0";s:8:"accounts";s:2:"81";s:5:"other";a:1:{s:9:"Load (1m)";
    a:2:{i:0;s:1:"f";i:1;d:0.12;}}}}}

Example implementation in a PHP script:

<?php
$output = `/usr/local/centovacast/sbin/sumanage version --outputmode=serialize`;
if (!is_array($result = unserialize($output))) die("Bad output\n");
if (!$result['successful']) die('Error: '.$result['message']."\n");
echo 'Centova Cast version is ' . $result['data']['web']['version']."\n";

PHP Statement

Selected using --outputmode=php, this mode generates output as a PHP array() statement which may be directly included in a PHP script.

Example output from ccmanage version --outputmode=php:

array (
    'successful' => 1,
    'message' => 'Centova Cast v3.0.0',
    'data' =>
        array (
            'web' =>
                    array (
                    'version' => '3.0.0',
                    'accounts' => '81',
                    'other' =>
                        array (
                            'Load (1m)' =>
                                array (
                                    0 => 'f',
                                    1 => 0.08,
                                ),
                        ),
                ),
        ),
)

Example implementation in PHP a script (not recommended):

<?php
$output = `/usr/local/centovacast/sbin/sumanage version --outputmode=php`;
$result = eval('return '.$output.';');
if (!$result['successful']) die('Error: '.$result['message']."\n");
echo 'Centova Cast version is ' . $result['data']['web']['version']."\n";

JSON

Selected using --outputmode=json, this mode generates output using JavaScript Object Notation (JSON).

Example output from ccmanage version --outputmode=json:

{
        "successful":1,
        "message":"Centova Cast v3.0.0",
        "data":{
                "web":{
                        "version":"3.0.0",
                        "accounts":81,
                        "other":{
                                "Load (1m)":[
                                        "f",
                                        0.1700
                                ]
                        }
                }
        }
}

Example implementation in a Python script:

import sys, subprocess, json

p = subprocess.Popen(["/usr/local/centovacast/sbin/sumanage","version","--outputmode=json"], stdout=subprocess.PIPE)
output, error = p.communicate()
result = json.loads(output)

if result['successful'] != 1:
    print u'Error:', result['message']
    sys.exit(1)

print u'Centova Cast version is', result['data']['web']['version']

XML

Selected using --outputmode=xml, this mode generates output in XML format.

Example output from ccmanage version --outputmode=xml:

<?xml version="1.0" encoding="UTF-8" ?>
<result>
  <successful>1</successful>
  <message>Centova Cast v3.0.0</message>
  <data>
    <web>
      <version>3.0.0</version>
      <accounts>81</accounts>
      <other>
        <Load1m>
          <node>f</node>
          <node>0.14</node>
        </Load1m>
      </other>
    </web>
  </data>
</result>

Example implementation in a Ruby script:

require 'rexml/document'

output = `/usr/local/centovacast/sbin/sumanage version --outputmode=xml`
doc = REXML::Document.new(output)

if doc.root.elements["successful"].text != "1"
        puts "Error: " + doc.root.elements["message"].text
        exit 1
end

puts "Centova Cast version is " + doc.root.elements["data/web/version"].text

CSV Spreadsheet

Selected using --outputmode=csv, this mode generates output in CSV (comma-separated value) format. Note that due to the limitations of this format, it is only usable with commands that return a flat list of values; attempting to CSV mode with commands that return nested data structures will result in an error message.

Example output from ccmanage usage all --outputmode=csv:

username,diskquota,transferlimit,diskusage,transferusage
rockstream,5000,100000,3875,75325
popstream,7500,150000,4925,107350
~result,OK,"Check complete"

Example of generating a plain-English report from the CSV data using the awk utility:

/usr/local/centovacast/sbin/sumanage usage all --outputmode=csv \
    | awk -F ',' 'NR>1 && $1 !~ /^~/ {print "User " $1 " has used "
        $4 "/" $2 "MB of disk space and " $5 "/" $3 "MB of data transfer."}'