Samples

All languages with the capability to use a HTTP client can be used to get information from WebSphere MQ using the MQWeb HTTP server. On this page you get an overview of all samples that are available for MQWeb.

PHP
Perl
Python
Ruby
JavaScript
Java

PHP

With PHP you can use the curl module, Guzzle or any other http client implementation.

Authentication Information

Inquire
<?php
	/*
	 * Inquire all SYSTEM authentication information objects from queuemanager 
	 * PIGEON. MQWeb runs on localhost and is listening on port 8081. 
	 */
	$url = "http://localhost:8081/api/authinfo/inquire/PIGEON/SYSTEM*";

	$curl = curl_init();
	curl_setopt($curl, CURLOPT_URL, $url);
	curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);

	if ( ($response = curl_exec($curl)) === false )	{
		$err = curl_error($curl);
		echo "An HTTP error occurred while inquiring authentication information: $err\n";
	}
	else {
		$json = json_decode($response);
		if ( isset($json->error) ) {
			echo "An MQ error occurred while inquiring authentication information objects.\n";
			echo "Reason Code: {$json->error->reason->code} - {$json->error->reason->desc}\n";
		}
		else {
			if ( isset($json->data) && count($json->data) > 0 ) {
				foreach($json->data as $authinfo)
				{
					echo $authinfo->AuthInfoName->value;
					echo "\n";
				}
			}
			else
			{
				echo "No authentication information objects found\n";
			}
		}
	}

Authority Records

Inquire
<?php
	/*
	 * Inquire all authority records for queuemanager PIGEON.
	 * MQWeb runs on localhost and is listening on port 8081. 
	 */
	$url = "http://localhost:8081/api/authrec/inquire/PIGEON/?Options=Name%20All%20Matching&Options=Entity%20Explicit";

	$curl = curl_init();
	curl_setopt($curl, CURLOPT_URL, $url);
	curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);

	if ( ($response = curl_exec($curl)) === false )	{
		$err = curl_error($curl);
		echo "An HTTP error occurred while getting authority records: $err\n";
	}
	else {
		$json = json_decode($response);
		if ( isset($json->error) ) {
			echo "An MQ error occurred while inquiring authority records.\n";
			echo "Reason Code: {$json->error->reason->code} - {$json->error->reason->desc}\n";
		}
		else {
			if ( isset($json->data) && count($json->data) > 0 ) {
				foreach($json->data as $authrec)
				{
					echo $authrec->ProfileName->value;
					echo '(';
					echo $authrec->ObjectType->display;
					echo ')';
					echo ' - ';
					echo $authrec->EntityName->value;
					echo "\n";
					
					$authorizations = array();
					foreach($authrec->AuthorizationList->value as $authorization)
					{
						$authorizations[] = $authorization->display;
					}
					echo "   ";
					echo join(', ', $authorizations);
					echo "\n";
				}
			}
			else
			{
				echo "No authority records found\n";
			}
		}
	}

Channels

Inquire
<?php

	/*
	 * Inquire all client channels from queuemanager PIGEON.
	 * MQWeb runs on localhost and is listening on port 8081. 
	 */
	$url = "http://localhost:8081/api/channel/inquire/PIGEON/*/Server-connection";

	$curl = curl_init();
	curl_setopt($curl, CURLOPT_URL, $url);
	curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);

	if ( ($response = curl_exec($curl) ) === false ) {
		$err = curl_error($curl);
		echo "An HTTP error occurred while inquiring channel information: $err\n";
	}
	else {
		$json = json_decode($response);
		if ( isset($json->error) ) {
			echo "An MQ error occurred while inquiring channels.\n";
			echo "Reason Code: {$json->error->reason->code} - {$json->error->reason->desc}\n";
		}
		else {
			if ( isset($json->data) && count($json->data) > 0 ) {
				foreach($json->data as $channel)
				{
					echo $channel->ChannelName->value;
					echo "\n";
				}
			}
			else
			{
				echo "No client channels found\n";
			}
		}
	}

Channel Statuses

Inquire
<?php
	/*
	 * Inquire all server connection channel statuses for queuemanager PIGEON.
	 * MQWeb runs on localhost and is listening on port 8081. 
	 */
	$url = "http://localhost:8081/api/chstatus/inquire/PIGEON?ChannelType=Server-connection";
	
	$curl = curl_init();
	curl_setopt($curl, CURLOPT_URL, $url);
	curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
	
	if ( ($response = curl_exec($curl)) === false )	{
		$err = curl_error($curl);
		echo "An HTTP error occurred while inquiring channel status information: $err\n";
	}
	else {
		$json = json_decode($response);
		if ( isset($json->error) ) {
			echo "An MQ error occurred while inquiring channel statuses.\n";
			echo "Reason Code: {$json->error->reason->code} - {$json->error->reason->desc}\n";
		}
		else {
			if ( isset($json->data) && count($json->data) > 0 ) {
				foreach($json->data as $status)
				{
					echo $status->ChannelName->value;
					echo " : ";
					echo $status->ChannelStatus->display;
					echo "\n";
				}
			}
			else
			{
				echo "No statuses found\n";
			}
		}
	}

Cluster Queuemanager

Inquire
<?php

	/*
	 * Inquire all cluster information from queuemanager PIGEON.
	 * MQWeb runs on localhost and is listening on port 8081. 
	 */
	$url = "http://localhost:8081/api/clusqmgr/inquire/PIGEON";

	$curl = curl_init();
	curl_setopt($curl, CURLOPT_URL, $url);
	curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);

	if ( ($response = curl_exec($curl)) === false )	{
		$err = curl_error($curl);
		echo "An HTTP error occurred while inquiring cluster queuemanagers: $err\n";
	}
	else {
		$json = json_decode($response);
		if ( isset($json->error) ) {
			echo "An MQ error occurred while inquiring cluster queuemanagers.\n";
			echo "Reason Code: {$json->error->reason->code} - {$json->error->reason->desc}\n";
		}
		else {
			if ( isset($json->data) && count($json->data) > 0 ) {
				foreach($json->data as $clusqmgr)
				{
					echo $clusqmgr->ClusterName->value;
					echo " : ";
					echo $clusqmgr->QMgrName->value;
					echo "\n";
				}
			}
			else
			{
				echo "No cluster queuemanagers found\n";
			}
		}
	}
Suspend
<?php

	/*
	 * Suspend queuemanager PIGEON in cluster BIRDS.
	 * MQWeb runs on localhost and is listening on port 8081. 
	 */
	$url = 'http://localhost:8081/api/clusqmgr/suspend/PIGEON/BIRDS';

	$curl = curl_init();
	curl_setopt($curl, CURLOPT_URL, $url);
	curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);

	if ( ($response = curl_exec($curl)) === false )	{
		$err = curl_error($curl);
		echo 'An HTTP error occurred while suspending: ', $err, PHP_EOL;
	}
	else {
		$json = json_decode($response);
		if ( isset($json->error) ) {
			echo 'An MQ error occurred while suspending.', PHP_EOL;
			echo 'Reason Code: ',
				$json->error->reason->code,
				' - ',
				$json->error->reason->desc, 
				PHP_EOL;
		}
		else {
			echo 'Queuemanager PIGEON suspended in clusterd BIRDS', PHP_EOL;
		}
	}
Resume
<?php

	/*
	 * Resume queuemanager PIGEON in cluster BIRDS.
	 * MQWeb runs on localhost and is listening on port 8081. 
	 */
	$url = 'http://localhost:8081/api/clusqmgr/resume/PIGEON/BIRDS';

	$curl = curl_init();
	curl_setopt($curl, CURLOPT_URL, $url);
	curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);

	if ( ($response = curl_exec($curl)) === false )	{
		$err = curl_error($curl);
		echo 'An HTTP error occurred while trying to resume: ', $err, PHP_EOL;
	}
	else {
		$json = json_decode($response);
		if ( isset($json->error) ) {
			echo 'An MQ error occurred while trying to resume.', PHP_EOL;
			echo 'Reason Code: ', 
				$json->error->reason->code,
				' - ', 
				$json->error->reason->desc,
				PHP_EOL;
		}
		else {
			echo 'Queuemanager PIGEON resumed in clusterd BIRDS', PHP_EOL;
		}
	}

Listeners

Inquire
<?php
	/*
	 * Inquire all SYSTEM listeners with transporttype TCP from queuemanager 
	 * PIGEON. MQWeb runs on localhost and is listening on port 8081. 
	 */
	$url = "http://localhost:8081/api/listener/inquire/PIGEON/SYSTEM*/TCP";

	$curl = curl_init();
	curl_setopt($curl, CURLOPT_URL, $url);
	curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);


	$response = curl_exec($curl);
	$data = json_decode($response, true);		
	print_r($data);

Listener Statuses

Inquire
<?php
	/*
	 * Inquire status of all listeners from queuemanager 
	 * PIGEON. MQWeb runs on localhost and is listening on port 8081. 
	 */
	$url = "http://localhost:8081/api/lsstatus/inquire/PIGEON";

	$curl = curl_init();
	curl_setopt($curl, CURLOPT_URL, $url);
	curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);

	$response = curl_exec($curl);
	$data = json_decode($response, true);		
	print_r($data);

Namelists

Inquire
<?php
	/*
	 * This sample will show all SYSTEM namelists from queuemanager PIGEON with
	 * their description.
	 * MQWeb runs on localhost and is listening on port 8081. 
	 */
	$url = "http://localhost:8081/api/nl/inquire/PIGEON/SYSTEM*";

	$curl = curl_init();
	curl_setopt($curl, CURLOPT_URL, $url);
	curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);

	if ( ($response = curl_exec($curl)) === false )	{
		$err = curl_error($curl);
		echo "An HTTP error occurred while getting namelist information: $err\n";
	}
	else {
		$json = json_decode($response);
		if ( isset($json->error) ) {
			echo "An MQ error occurred while inquiring namelist.\n";
			echo "Reason Code: {$json->error->reason->code} - {$json->error->reason->desc}\n";
		}
		else {
			if ( isset($json->data) && count($json->data) > 0 ) {
				foreach($json->data as $namelist)
				{
					echo $namelist->NamelistName->value;
					echo ': ';
					echo $namelist->NamelistDesc->value;
					echo "\n";
				}
			}
			else
			{
				echo "No namelists found\n";
			}
		}
	}

Processes

Inquire
<?php
	/*
	 * This sample will show all SYSTEM processes.
	 * MQWeb runs on localhost and is listening on port 8081. 
	 */
	$url = "http://localhost:8081/api/process/inquire/PIGEON/SYSTEM*";

	$curl = curl_init();
	curl_setopt($curl, CURLOPT_URL, $url);
	curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);

	if ( ($response = curl_exec($curl)) === false )	{
		$err = curl_error($curl);
		echo "An HTTP error occurred while getting process information: $err\n";
	}
	else {
		$json = json_decode($response);
		if ( isset($json->error) ) {
			echo "An MQ error occurred while inquiring processes.\n";
			echo "Reason Code: {$json->error->reason->code} - {$json->error->reason->desc}\n";
		}
		else {
			if ( isset($json->data) && count($json->data) > 0 ) {
				foreach($json->data as $process)
				{
					echo $process->ProcessName->value;
					echo "\n";
				}
			}
			else
			{
				echo "No processes found\n";
			}
		}
	}

QueueManager

Inquire
<?php
	/*
	 * This sample will show the description of queuemanager PIGEON.
	 * MQWeb runs on localhost and is listening on port 8081. 
	 */
	$url = "http://localhost:8081/api/qmgr/inquire/PIGEON";

	$curl = curl_init();
	curl_setopt($curl, CURLOPT_URL, $url);
	curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);

	if ( ($response = curl_exec($curl)) === false )	{
		$err = curl_error($curl);
		echo 'An HTTP error occurred while inquiring queuemanager status: '
			. $err
			. PHP_EOL;
	}
	else {
		$json = json_decode($response);
		if ( isset($json->error) ) {
			echo 'An MQ error occurred while inquiring queuemanager status.'
				. PHP_EOL;
			echo 'Reason Code: '
				. $json->error->reason->code
				. ' - '
				. $json->error->reason->desc
				. PHP_EOL;
		}
		else {
			if ( isset($json->data) && count($json->data) > 0 ) {
				echo $json->data[0]->QMgrName->value
					. ' : '
					. $json->data[0]->QMgrDesc->value
					. PHP_EOL;
			}
			else {
				echo 'No qmgr found' . PHP_EOL;
			}
		}
	}

QueueManager Status

Inquire
<?php
	/*
	 * This sample will show the startdate/time of queuemanager PIGEON.
	 * MQWeb runs on localhost and is listening on port 8081. 
	 */
	$url = "http://localhost:8081/api/qmstatus/inquire/PIGEON";

	$curl = curl_init();
	curl_setopt($curl, CURLOPT_URL, $url);
	curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);

	if ( ($response = curl_exec($curl)) === false )	{
		$err = curl_error($curl);
		echo 'An HTTP error occurred while inquiring queuemanager status: '
			. $err
			. PHP_EOL;
	}
	else {
		$json = json_decode($response);
		if ( isset($json->error) ) {
			echo 'An MQ error occurred while inquiring queuemanager status.'
				. PHP_EOL;
			echo 'Reason Code: '
				. $json->error->reason->code
				. ' - '
				. $json->error->reason->desc
				. PHP_EOL;
		}
		else {
			if ( isset($json->data) && count($json->data) > 0 ) {
				echo $json->data[0]->QMgrName->value
					. ' started on '
					. $json->data[0]->StartDate->value
					. ' '
					. $json->data[0]->StartTime->value
					. PHP_EOL;
			}
			else {
				echo 'No status found' . PHP_EOL;
			}
		}
	}

Queues

Inquire
<?php
	/*
	 * This sample will show all SYSTEM queues from queuemanager PIGEON and
	 * prints the current queue depth if this property exists for the queue.
	 * MQWeb runs on localhost and is listening on port 8081. 
	 */
	$url = "http://localhost:8081/api/queue/inquire/PIGEON/SYSTEM*";

	$curl = curl_init();
	curl_setopt($curl, CURLOPT_URL, $url);
	curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);

	if ( ($response = curl_exec($curl)) === false )	{
		$err = curl_error($curl);
		echo "An HTTP error occurred while getting queue information: $err\n";
	}
	else {
		$json = json_decode($response);
		if ( isset($json->error) ) {
			echo "An MQ error occurred while inquiring queues.\n";
			echo "Reason Code: {$json->error->reason->code} - {$json->error->reason->desc}\n";
		}
		else {
			if ( isset($json->data) && count($json->data) > 0 ) {
				foreach($json->data as $queue)
				{
					echo $queue->QName->value;
					if ( isset($queue->CurrentQDepth) ) {
						echo ': ' . $queue->CurrentQDepth->value;
					}
					echo "\n";
				}
			}
			else
			{
				echo "No queues found\n";
			}
		}
	}
Inquire (with Guzzle)
<?php

// Don't forget to install Guzzle before running this sample!
// All info: http://docs.guzzlephp.org/

require_once 'vendor/autoload.php';
use Guzzle\Http\Client;

// Create a client and provide a base URL
$client = new Client('http://localhost:8081');
$data = $client->get('api/queue/inquire/PIGEON')->send()->json();
print_r($data);

Services

Inquire
<?php
	/*
	 * This sample will show all SYSTEM services.
	 * MQWeb runs on localhost and is listening on port 8081. 
	 */
	$url = "http://localhost:8081/api/service/inquire/PIGEON/SYSTEM*";

	$curl = curl_init();
	curl_setopt($curl, CURLOPT_URL, $url);
	curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);

	if ( ($response = curl_exec($curl)) === false )	{
		$err = curl_error($curl);
		echo "An HTTP error occurred while getting service information: $err\n";
	}
	else {
		$json = json_decode($response);
		if ( isset($json->error) ) {
			echo "An MQ error occurred while inquiring services.\n";
			echo "Reason Code: {$json->error->reason->code} - {$json->error->reason->desc}\n";
		}
		else {
			if ( isset($json->data) && count($json->data) > 0 ) {
				foreach($json->data as $service)
				{
					echo $service->ServiceName->value;
					echo "\n";
				}
			}
			else
			{
				echo "No services found\n";
			}
		}
	}

Topics

Inquire
<?php
/*
 * This sample will show all topics from a queuemanager.
 * MQWeb runs on localhost and is listening on port 8081. 
 */
if ( count($argv) < 2 ) {
	echo 'Please pass a queuemanager name as argument', PHP_EOL;
	exit;
}

$qmgr = $argv[1];

$url = 'http://localhost:8081/api/topic/inquire/' . $qmgr . '/*';

$curl = curl_init();
curl_setopt($curl, CURLOPT_URL, $url);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);

if ( ($response = curl_exec($curl)) === false )	{
	$err = curl_error($curl);
	echo 'An HTTP error occurred while getting topic information from '
		, $qmgr
		, ': '
		, $err
		, PHP_EOL;
}
else {
	$json = json_decode($response);
	
	// When there is an error object returned, something went wrong with
	// the WebSphere MQ command.
	if ( isset($json->error) ) {
		echo 'An MQ error occurred while inquiring topics from '
			, $qmgr
			, PHP_EOL;
		echo 'Reason Code: '
			,	$json->error->reason->code
			, " - "
			, $json->error->reason->desc
			, PHP_EOL;
	}
	else {
		echo 'Topics on ', $qmgr, PHP_EOL;
		echo '----------', str_repeat('-', strlen($qmgr)), PHP_EOL;
		if ( isset($json->data) && count($json->data) > 0 ) {
			foreach($json->data as $topic)
			{
				echo $topic->TopicName->value, PHP_EOL;
			}
		}
		else
		{
			echo 'No topics found', PHP_EOL;
		}
	}
}

Perl

With Perl you can use LWP together with HTTP::Request::Common and JSON or any other http client implementation.

Authentication Information

Inquire
#!/usr/bin/perl
use strict;
use warnings;
use feature qw(say);

use JSON;
use LWP::UserAgent;
use HTTP::Request::Common;

# This sample will show all SYSTEM authentication information objects.

my $qmgr = shift;
die("Please pass me the name of a queuemanager as argument") 
	unless defined($qmgr);

my $json = JSON->new;

my %input = ( 
	'AuthInfoName' => 'SYSTEM*'
);
my $content = $json->encode(\%input);    

my $ua = LWP::UserAgent->new;
my $req = POST 'http://localhost:8081/api/authinfo/inquire/' . $qmgr;
$req->header(
	'Content-Type' => 'application/json',
	'Content-length' => length($content)
);
$req->content($content);

my $res = $ua->request($req);
die $res->status_line unless $res->is_success;
	
my $mqweb = $json->decode($res->content());
if ( exists($mqweb->{error}) ) {
	say 'An MQ error occurred while inquiring queues.';
	say 'Reason Code: '
		, $mqweb->{error}->{reason}->{code}
		, ' - '
		, $mqweb->{error}->{reason}->{desc};
}
else {
	foreach my $authinfo(@{$mqweb->{data}}) {
		say $authinfo->{AuthInfoName}->{value};
	}
}

Authority Records

Inquire
#!/usr/bin/perl
use strict;
use warnings;
use feature qw(say);

use JSON;
use LWP::UserAgent;
use HTTP::Request::Common;

# This sample will show all authentication records and will list
# the profilename together with the entityname and the given authorizations.

my $qmgr = shift;
die("Please pass me the name of a queuemanager as argument") 
	unless defined($qmgr);

my $json = JSON->new;

my %input = ( 
	'Options' => [ 
		'Name All Matching', 
		'Entity Explicit'
	]
);
my $content = $json->encode(\%input);    

my $ua = LWP::UserAgent->new;
my $req = POST 'http://localhost:8081/api/authrec/inquire/' . $qmgr;
$req->header(
	'Content-Type' => 'application/json',
	'Content-length' => length($content)
);
$req->content($content);

my $res = $ua->request($req);
die $res->status_line unless $res->is_success;

my $mqweb = $json->decode($res->content());
if ( exists($mqweb->{error}) ) {
	say 'An MQ error occurred while inquiring queues.';
	say 'Reason Code: '
		, $mqweb->{error}->{reason}->{code}
		, ' - '
		, $mqweb->{error}->{reason}->{desc};
}
else {
	foreach my $authrec(@{$mqweb->{data}}) {
		my $output = $authrec->{ProfileName}->{value};
		$output .= '(' . $authrec->{ObjectType}->{display} . ')';
		$output .= ' - ' . $authrec->{EntityName}->{value};

		my @authorizations = ();
		foreach my $authority(@{$authrec->{AuthorizationList}->{value}}) {
			push(@authorizations, $authority->{display});
		}
		$output .= ' : ' . join(', ', @authorizations);

		say $output;
	}
}

Channels

Inquire
#!/usr/bin/perl
use strict;
use warnings;
use feature qw(say);

use JSON;
use LWP::UserAgent;
use HTTP::Request::Common;

# Get all channels and list them with the channeltype and connectionname (if
# available

my $qmgr = shift;
die("Please pass me the name of a queuemanager as argument") 
	unless defined($qmgr);

my $json = JSON->new;

my %input = ( 
	'ChannelName' => '*',
	'ChannelAttrs' => [ 
		'ConnectioName'
		# No need to specify ChannelName and ChannelType, they are always
		# returned.
	]
);
my $content = $json->encode(\%input);    

my $ua = LWP::UserAgent->new;
my $req = POST 'http://localhost:8081/api/channel/inquire/' . $qmgr;    
$req->header(
	'Content-Type' => 'application/json',
	'Content-length' => length($content)
);
$req->content($content);

my $res = $ua->request($req);
die $res->status_line unless $res->is_success;

my $mqweb = $json->decode($res->content());
if ( exists($mqweb->{error}) ) {
	say 'An MQ error occurred while inquiring queues.';
	say 'Reason Code: '
		, $mqweb->{error}->{reason}->{code}
		, ' - '
		, $mqweb->{error}->{reason}->{desc};
}
else {
	foreach my $channel(@{$mqweb->{data}}) {
		my $output = $channel->{ChannelName}->{value};
		$output .= '(' . $channel->{ChannelType}->{display} . ')';
		if ( exists($channel->{ConnectionName}) ) {
			my $connectionName = $channel->{ConnectionName}->{value};
			if ( length($connectionName) > 0 ) {
				$output .= ' : ' . $connectionName;
			}
			else {
				$output .= ' : - ';
			}
		}
		say $output;
	}
}

Channel Statuses

Inquire
#!/usr/bin/perl
use strict;
use warnings;
use feature qw(say);

use JSON;
use LWP::UserAgent;
use HTTP::Request::Common;

# Get the channelstatus for all cluster sender channels

my $qmgr = shift;
die("Please pass me the name of a queuemanager as argument")
	unless defined($qmgr);

my $json = JSON->new;

my %input = ( 
  'ChannelName' => '*',
  'IntegerFilterCommand' => {
  	'Parameter' => 'ChannelType',
  	'Operator' => 'EQ',
  	'FilterValue' => 'Cluster-sender'
  }
);
my $content = $json->encode(\%input);    

my $ua = LWP::UserAgent->new;
my $req = POST 'http://localhost:8081/api/chstatus/inquire/' . $qmgr;    
$req->header(
	'Content-Type' => 'application/json',
	'Content-length' => length($content)
);
$req->content($content);

my $res = $ua->request($req);
die $res->status_line unless $res->is_success;

my $mqweb = $json->decode($res->content());
if ( exists($mqweb->{error}) ) {
	say 'An MQ error occurred while inquiring queues.';
	say 'Reason Code: '
		, $mqweb->{error}->{reason}->{code}
		, ' - '
		, $mqweb->{error}->{reason}->{desc};
}
else {
	foreach my $status(@{$mqweb->{data}}) {
		say $status->{ChannelName}->{value}
			, ' : '
			, $status->{ChannelStatus}->{display}
	}
}

Listeners

Inquire
#!/usr/bin/perl
use strict;
use warnings;
use feature qw(say);

use JSON;
use LWP::UserAgent;
use HTTP::Request::Common;

# This sample shows all listeners with the properties ListenerName and 
# TransportType

my $qmgr = shift;
die("Please pass me the name of a queuemanager as argument") 
	unless defined($qmgr);

my $json = JSON->new;

my %input = ( 
	'ListenerName' => '*',
	'ListenerAttrs' => [ 
		'ListenerName', # Can be omitted, because it is always returned 
		'TransportType'
	]
);

my $content = $json->encode(\%input);    

my $ua = LWP::UserAgent->new;
my $req = POST 'http://localhost:8081/api/listener/inquire/' . $qmgr;    
$req->header(
	'Content-Type' => 'application/json',
	'Content-length' => length($content)
);
$req->content($content);

my $res = $ua->request($req);
die $res->status_line unless $res->is_success;

my $mqweb = $json->decode($res->content());
if ( exists($mqweb->{error}) ) {
	say 'An MQ error occurred while inquiring listeners.';
	say 'Reason Code: '
		, $mqweb->{error}->{reason}->{code}
		, ' - '
		, $mqweb->{error}->{reason}->{desc};
}
else {
	foreach my $listener(@{$mqweb->{data}}) {
		say $listener->{ListenerName}->{value}
			, ' - '
			, $listener->{TransportType}->{display};
	}
}

Listener Statuses

Inquire
#!/usr/bin/perl
use strict;
use warnings;
use JSON;
use LWP::UserAgent;
use HTTP::Request::Common;

# This sample will show the status of all listeners

my $qmgr = shift;
die("Please pass me the name of a queuemanager as argument") 
	unless defined($qmgr);

my $json = JSON->new;

# There's no need to set ListenerName to * because this is the default,
# but we do it here to show how to build the json content.
my %input = ( 
	'ListenerName' => '*',
);
my $content = $json->encode(\%input);    

my $ua = LWP::UserAgent->new;
my $req = POST 'http://localhost:8081/api/lsstatus/inquire/' . $qmgr;
$req->header(
	'Content-Type' => 'application/json',
	'Content-length' => length($content)
);
$req->content($content);

my $res = $ua->request($req);
die $res->status_line unless $res->is_success;

my $mqweb = $json->decode($res->content());
if ( exists($mqweb->{error}) ) {
	say 'An MQ error occurred while inquiring listener status.';
	say 'Reason Code: '
		, $mqweb->{error}->{reason}->{code}
		, ' - '
		, $mqweb->{error}->{reason}->{desc};
}}
else {
	foreach my $status(@{$mqweb->{data}}) {
		print $status->{ListenerName}->{value};
		print ' : ', $status->{Status}->{display}; 
		print "\n";
	}
}

Namelists

Inquire
#!/usr/bin/perl
use strict;
use warnings;
use feature qw(say);

use JSON;
use LWP::UserAgent;
use HTTP::Request::Common;

# Sample that shows all namelists with their names

my $qmgr = shift;
die("Please pass me the name of a queuemanager as argument") 
	unless defined($qmgr);

my $json = JSON->new;

my %input = (
	'NamelistName' => '*' 
);
my $content = $json->encode(\%input);    

my $ua = LWP::UserAgent->new;
my $req = POST 'http://localhost:8081/api/nl/inquire/' . $qmgr;    
$req->header(
	'Content-Type' => 'application/json',
	'Content-length' => length($content)
);
$req->content($content);

my $res = $ua->request($req);
die $res->status_line unless $res->is_success;

my $mqweb = $json->decode($res->content());
if ( exists($mqweb->{error}) ) {
	say 'An MQ error occurred while inquiring listeners.';
	say 'Reason Code: '
		, $mqweb->{error}->{reason}->{code}
		, ' - '
		, $mqweb->{error}->{reason}->{desc};
}
else {
	foreach my $namelist(@{$mqweb->{data}}) {
		say $namelist->{NamelistName}->{value};
		my @names = @{$namelist->{Names}->{value}};
		foreach my $name(@names) {
			say '  ', $name;
		}
	}
}

Processes

Inquire
#!/usr/bin/perl
use strict;
use warnings;
use feature qw(say);

use JSON;
use LWP::UserAgent;
use HTTP::Request::Common;

# Shows all SYSTEM processes

my $qmgr = shift;
die("Please pass me the name of a queuemanager as argument") 
	unless defined($qmgr);

my $json = JSON->new;

my %input = ( 
	'ProcessName' => 'SYSTEM*'
);

my $content = $json->encode(\%input);    

my $ua = LWP::UserAgent->new;
my $req = POST 'http://localhost:8081/api/process/inquire/' . $qmgr;    
$req->header(
	'Content-Type' => 'application/json',
	'Content-length' => length($content)
);
$req->content($content);

my $res = $ua->request($req);
die $res->status_line unless $res->is_success;

my $mqweb = $json->decode($res->content());
if ( exists($mqweb->{error}) ) {
	say 'An MQ error occurred while inquiring processes.';
	say 'Reason Code: '
		, $mqweb->{error}->{reason}->{code}
		, ' - '
		, $mqweb->{error}->{reason}->{desc};
}
else {
	foreach my $process(@{$mqweb->{data}}) {
		say $process->{ProcessName}->{value};
	}
}

QueueManager

Inquire
#!/usr/bin/perl
use strict;
use warnings;
use JSON;
use LWP::UserAgent;
use HTTP::Request::Common;
use feature qw(say);

# This sample will show the description of the queuemanager

my $qmgr = shift;
die("Please pass me the name of a queuemanager as argument") 
	unless defined($qmgr);

my $json = JSON->new;

my %input = ( 
	'QMgrAttrs' => [
		'QMgrDesc'
	],
);
my $content = $json->encode(\%input);    

my $ua = LWP::UserAgent->new;
my $req = POST 'http://localhost:8081/api/qmgr/inquire/' . $qmgr;
$req->header(
	'Content-Type' => 'application/json',
	'Content-length' => length($content)
);
$req->content($content);

my $res = $ua->request($req);
die $res->status_line unless $res->is_success;

my $mqweb = $json->decode($res->content());
if ( exists($mqweb->{error}) ) {
	say 'An MQ error occurred while inquiring queuemanager.';
	say	'Reason Code: ',
		$mqweb->{error}->{reason}->{code},
		' - ',
		$mqweb->{error}->{reason}->{desc};
}
else {
	say $mqweb->{data}->[0]->{QMgrName}->{value},
		' : ', 
		$mqweb->{data}->[0]->{QMgrDesc}->{value};
}

QueueManager Status

Inquire
#!/usr/bin/perl
use strict;
use warnings;
use feature qw(say);

use JSON;
use LWP::UserAgent;
use HTTP::Request::Common;

my $qmgr = shift;
die("Please pass me the name of a queuemanager as argument") unless defined($qmgr);

my $json = JSON->new;

my %input = ( 
);

my $content = $json->encode(\%input);    

my $ua = LWP::UserAgent->new;
my $req = POST 'http://localhost:8081/api/qmstatus/inquire/' . $qmgr;    
$req->header(
	'Content-Type' => 'application/json',
	'Content-length' => length($content)
);
$req->content($content);

my $res = $ua->request($req);
die $res->status_line unless $res->is_success;

my $mqweb = $json->decode($res->content());
if ( exists($mqweb->{error}) ) {
	say 'An MQ error occurred while inquiring queuemanager status.';
	say	'Reason Code: ',
		$mqweb->{error}->{reason}->{code},
		' - ',
		$mqweb->{error}->{reason}->{desc};
}
else {
	say $mqweb->{data}->[0]->{QMgrName}->{value},
		' : ', 
		$mqweb->{data}->[0]->{QMgrStatus}->{text};
}

Queues

Inquire
#!/usr/bin/perl
use strict;
use warnings;
use feature qw(say);

use JSON;
use LWP::UserAgent;
use HTTP::Request::Common;

# This sample will show all SYSTEM queues from the given queuemanager and
# prints the current queue depth if this property exists for the queue.

my $qmgr = shift;
die("Please pass me the name of a queuemanager as argument") 
	unless defined($qmgr);

my $json = JSON->new;

my %input = ( 
	'QName' => 'SYSTEM*',
	'QAttrs' => [
		'CurrentQDepth'
		# No need to add QName, it is always returned
	]
);
my $content = $json->encode(\%input);    

my $ua = LWP::UserAgent->new;
my $req = POST 'http://localhost:8081/api/queue/inquire/' . $qmgr;
$req->header(
	'Content-Type' => 'application/json',
	'Content-length' => length($content)
);
$req->content($content);

my $res = $ua->request($req);
die $res->status_line unless $res->is_success;
	
my $mqweb = $json->decode($res->content());
if ( exists($mqweb->{error}) ) {
	say 'An MQ error occurred while inquiring queues.';
	say 'Reason Code: '
		, $mqweb->{error}->{reason}->{code}
		, ' - '
		, $mqweb->{error}->{reason}->{desc};
}
else {
	foreach my $queue(@{$mqweb->{data}}) {
		my $output = $queue->{QName}->{value};
		$output .= ' : ' . $queue->{CurrentQDepth}->{value} 
			if ( exists($queue->{CurrentQDepth}) );
		say $output;
	}
}

Services

Inquire
#!/usr/bin/perl
use strict;
use warnings;
use feature qw(say);

use JSON;
use LWP::UserAgent;
use HTTP::Request::Common;

# This sample will show all services

my $qmgr = shift;
die("Please pass me the name of a queuemanager as argument") unless defined($qmgr);

my $json = JSON->new;

my %input = ( 
	'ServiceName' => '*',
	'ServiceAttrs' => [ 'ServiceName' ] 
		# Not really needed, because ServiceName is always returned
		# but it shows how to set the ServiceAttrs property
);
my $content = $json->encode(\%input);

my $ua = LWP::UserAgent->new;
my $req = POST 'http://localhost:8081/api/service/inquire/' . $qmgr;
$req->header(
	'Content-Type' => 'application/json',
	'Content-length' => length($content)
);
$req->content($content);

my $res = $ua->request($req);
die $res->status_line unless $res->is_success;

my $mqweb = $json->decode($res->content());
if ( exists($mqweb->{error}) ) {
	say 'An MQ error occurred while inquiring services.';
	say 'Reason Code: '
		, $mqweb->{error}->{reason}->{code}
		, ' - '
		, $mqweb->{error}->{reason}->{desc};
}
else {
	foreach my $service(@{$mqweb->{data}}) {
		say $service->{ServiceName}->{value};
	}
}

Topics

Inquire
#!/usr/bin/perl
use strict;
use warnings;
use feature qw(say);

use JSON;
use LWP::UserAgent;
use HTTP::Request::Common;

# This sample will show all SYSTEM topics from the given queuemanager.

my $qmgr = shift;
die("Please pass me the name of a queuemanager as argument") 
	unless defined($qmgr);

my $json = JSON->new;

my %input = ( 
	'TopicName' => 'SYSTEM*'
);
my $content = $json->encode(\%input);    

my $ua = LWP::UserAgent->new;
my $req = POST 'http://localhost:8081/api/topic/inquire/' . $qmgr;
$req->header(
	'Content-Type' => 'application/json',
	'Content-length' => length($content)
);
$req->content($content);

my $res = $ua->request($req);
die $res->status_line unless $res->is_success;
	
my $mqweb = $json->decode($res->content());
if ( exists($mqweb->{error}) ) {
	say 'An MQ error occurred while inquiring topics.';
	say 'Reason Code: '
		, $mqweb->{error}->{reason}->{code}
		, ' - '
		, $mqweb->{error}->{reason}->{desc};
}
else {
	foreach my $topic(@{$mqweb->{data}}) {
		say $topic->{TopicName}->{value};
	}
}

Ruby

The Ruby Standard Library contains Net/HTTP that implements an HTTP client API for Ruby. Or you can use one of the HTTP clients from the Ruby Toolbox.

Queues

Inquire
require 'net/http'
require 'uri'
require 'json'
 
uri = URI.parse('http://localhost:8081/api/queue/inquire/PIGEON')
 
http = Net::HTTP.new(uri.host, uri.port)

begin
	response = http.request(Net::HTTP::Get.new(uri.request_uri))
rescue Errno::ECONNREFUSED
	puts "Can't connect to MQWeb. Is it running?"
	abort
end

if response.code == "200"
	json = JSON.parse(response.body)
	if json["error"]
		puts "An MQException occurred: RC= #{json["error"]["reason"]["code"]} - #{json["error"]["reason"]["desc"]}"
	else
		json["data"].each do |queue|
			puts queue["QName"]["value"]
		end
	end
else
	puts "A problem occurred with HTTP request: #{response.code}"
end

JavaScript

JavaScript can be used on the client side and on server side. In a browser you can use AJAJ to call the MQWeb API’s, on the server you can use nodejs to run your scripts.

Inquire
var http = require('http');

var options = {
	hostname : '127.0.0.1',
	port : 8081,
	path : '/api/queue/inquire/PIGEON',
	method : 'GET',
	headers : { 
	}
};

var req = http.request(options, function(res) {

	var output = '';

	res.setEncoding('utf8');

	res.on('data', function (data) {
		output += data;
	});

	res.on('end', function() {
		var json = JSON.parse(output);
		if ( json.error ) {
			console.log("An MQException occurred: RC= " + json.error.reason.code + " - " + json.error.reason.desc);
		}
		else {
			if ( json.data ) {
				for(q in json.data) {
					console.log(json.data[q].QName.value);
				}
			}
		}
	});
});

req.on('error', function(e) {
	console.log('problem with request: ' + e.message);
});

req.end();

Python

Authentication Information

Inquire
'''
 Inquire all SYSTEM authentication information objects from a queuemanager 
 MQWeb runs on localhost and is listening on port 8081. 
'''
import sys
import json
import httplib
import socket

if len(sys.argv) < 2 :
	print 'Please pass me the name of a queuemanager as argument'
	sys.exit(1)

url = "/api/authinfo/inquire/" + sys.argv[1] + '/SYSTEM*';

try:
	conn = httplib.HTTPConnection('localhost', 8081)
	conn.request('GET', url)
	res = conn.getresponse()
	result = json.loads(res.read())

	if 'error' in result:
		print ('Received a WebSphere MQ error: ' +	
			str(result['error']['reason']['code'])
		)
	else:
		if len(result['data']) == 0 :
			print "No authentication information found"
		else:
			for data in result['data']:
				print data['AuthInfoName']['value']

except httplib.HTTPException as e:
	print ('An HTTP error occurred while inquiring authentication information: ' +
		e.errno + e.strerror
	)
except socket.error as e:
	print e.strerror
	print 'Is the MQWeb daemon running?'

Authority Records

Inquire
'''
 Inquire all authority records for a queuemanager.
 MQWeb runs on localhost and is listening on port 8081. 
'''
import sys
import json
import httplib
import socket

if len(sys.argv) < 2 :
	print 'Please pass me the name of a queuemanager as argument'
	sys.exit(1)

url = '/api/authrec/inquire/' + sys.argv[1] + '/?Options=Name%20All%20Matching&Options=Entity%20Explicit'

try:
	conn = httplib.HTTPConnection('localhost', 8081)
	conn.request('GET', url)
	res = conn.getresponse()
	result = json.loads(res.read())

	if 'error' in result:
		print ('Received a WebSphere MQ error: ' +	
			str(result['error']['reason']['code'])
		)
	else:
		if len(result['data']) == 0:
			print "No authority records found"
		else:
			for data in result['data']:
				print(data['ProfileName']['value'] +
					'(' +
					data['ObjectType']['text'] +
					')' +
					' - ' +
					data['EntityName']['value']
				)
				print "   " + ', '.join([authorization['text'] for authorization in data['AuthorizationList']['value']])
except httplib.HTTPException as e:
	print ('An HTTP error occurred while inquiring authority services: ' +
		e.errno + e.strerror
	)
except socket.error as e:
	print e.strerror
	print 'Is the MQWeb daemon running?'

Authority Service

Inquire
'''
 Inquire all authority service information for a queuemanager.
 MQWeb runs on localhost and is listening on port 8081. 
'''
import sys
import json
import httplib
import socket

if len(sys.argv) < 2 :
	print 'Please pass me the name of a queuemanager as argument'
	sys.exit(1)

url = '/api/authservice/inquire/' + sys.argv[1]

try:
	conn = httplib.HTTPConnection('localhost', 8081)
	conn.request('GET', url)
	res = conn.getresponse()
	result = json.loads(res.read())

	if 'error' in result:
		print ('Received a WebSphere MQ error: ' +	
			str(result['error']['reason']['code'])
		)
	else:
		if len(result['data']) == 0:
			print "No authority services found"
		else:
			for data in result['data']:
				for service in data['ServiceComponent']['value']:
					print service
except httplib.HTTPException as e:
	print ('An HTTP error occurred while inquiring authority services: ' +
		e.errno + e.strerror
	)
except socket.error as e:
	print e.strerror
	print 'Is the MQWeb daemon running?'

Channels

Inquire
'''
 Inquire all server-connection channels from a queuemanager.
 MQWeb runs on localhost and is listening on port 8081. 
'''
import sys
import json
import httplib
import socket

if len(sys.argv) < 2 :
	print 'Please pass me the name of a queuemanager as argument'
	sys.exit(1)

url = '/api/channel/inquire/' + sys.argv[1] + '/*/Server-connection'

try:
	conn = httplib.HTTPConnection('localhost', 8081)
	conn.request('GET', url)
	res = conn.getresponse()
	result = json.loads(res.read())

	if 'error' in result:
		print ('Received a WebSphere MQ error: ' +	
			str(result['error']['reason']['code'])
		)
	else:
		if len(result['data']) == 0:
			print "No channels found"
		else:
			for data in result['data']:
				print data['ChannelName']['value']
except httplib.HTTPException as e:
	print ('An HTTP error occurred while inquiring channels: ' +
		e.errno + e.strerror
	)
except socket.error as e:
	print e.strerror
	print 'Is the MQWeb daemon running?'
Start
'''
 Starts a channel on a queuemanager 
 MQWeb runs on localhost and is listening on port 8081. 
'''
import sys
import json
import httplib
import socket

if len(sys.argv) < 3 :
	print 'Please pass me the name of a queuemanager and a channelname as argument'
	sys.exit(1)

url = "/api/channel/start/" + sys.argv[1] + '/' + sys.argv[2];

try:
	conn = httplib.HTTPConnection('localhost', 8081)
	conn.request('GET', url)
	res = conn.getresponse()
	result = json.loads(res.read())

	if 'error' in result:
		print ('Received a WebSphere MQ error: ' +	
			str(result['error']['reason']['code'])
		)
	else:
		print "Start command succesfully send."
		print "Note: this doesn't mean the channel is running! Use chstatus to get the status of the channel."

except httplib.HTTPException as e:
	print ('An HTTP error occurred while starting a channel: ' +
		e.errno + e.strerror
	)
except socket.error as e:
	print e.strerror
	print 'Is the MQWeb daemon running?'
Stop
'''
 Stops a channel on a queuemanager 
 MQWeb runs on localhost and is listening on port 8081. 
'''
import sys
import json
import httplib
import socket

if len(sys.argv) < 3 :
	print 'Please pass me the name of a queuemanager and a channelname as argument'
	sys.exit(1)

url = "/api/channel/stop/" + sys.argv[1] + '/' + sys.argv[2];

try:
	conn = httplib.HTTPConnection('localhost', 8081)
	conn.request('GET', url)
	res = conn.getresponse()
	result = json.loads(res.read())

	if 'error' in result:
		print ('Received a WebSphere MQ error: ' +	
			str(result['error']['reason']['code'])
		)
	else:
		print "Stop command succesfully send."

except httplib.HTTPException as e:
	print ('An HTTP error occurred while stopping the channel: ' +
		e.errno + e.strerror
	)
except socket.error as e:
	print e.strerror
	print 'Is the MQWeb daemon running?'

Channel Statuses

Inquire
'''
 Inquire all server connection channel statuses for a queuemanager.
 MQWeb runs on localhost and is listening on port 8081.
'''
import sys
import json
import httplib
import socket

if len(sys.argv) < 2 :
	print 'Please pass me the name of a queuemanager as argument'
	sys.exit(1)

url = '/api/chstatus/inquire/' + sys.argv[1] + '?ChannelType=Server-connection'

try:
	conn = httplib.HTTPConnection('localhost', 8081)
	conn.request('GET', url)
	res = conn.getresponse()
	result = json.loads(res.read())

	if 'error' in result:
		print ('Received a WebSphere MQ error: ' +	
			str(result['error']['reason']['code'])
		)
	else:
		if len(result['data']) == 0:
			print "No channelstatus found"
		else:
			for data in result['data']:
				print (data['ChannelName']['value'] + ': ' 
					+ data['ChannelStatus']['text']
				)
except httplib.HTTPException as e:
	print ('An HTTP error occurred while inquiring channel statuses: ' +
		e.errno + e.strerror
	)
except socket.error as e:
	print e.strerror
	print 'Is the MQWeb daemon running?'

Cluster Queuemanager

Inquire
'''
 Inquire all cluster information from a queuemanager.
 MQWeb runs on localhost and is listening on port 8081. 
'''
import sys
import json
import httplib
import socket

if len(sys.argv) < 2 :
	print 'Please pass me the name of a queuemanager as argument'
	sys.exit(1)

url = '/api/clusqmgr/inquire/' + sys.argv[1]

try:
	conn = httplib.HTTPConnection('localhost', 8081)
	conn.request('GET', url)
	res = conn.getresponse()
	result = json.loads(res.read())

	if 'error' in result:
		print ('Received a WebSphere MQ error: ' +	
			str(result['error']['reason']['code'])
		)
	else:
		if len(result['data']) == 0:
			print "No cluster queuemanagers found"
		else:
			for data in result['data']:
				print (data['ClusterName']['value'] + ': ' 
					+ data['QMgrName']['value']
				)
except httplib.HTTPException as e:
	print ('An HTTP error occurred while inquiring cluster queuemanagers: ' +
		e.errno + e.strerror
	)
except socket.error as e:
	print e.strerror
	print 'Is the MQWeb daemon running?'
Resume
'''
 Resumes a queuemanager in a cluster 
 MQWeb runs on localhost and is listening on port 8081. 
'''
import sys
import json
import httplib
import socket

if len(sys.argv) < 3 :
	print 'Please pass me the name of a queuemanager and a clustername as argument'
	sys.exit(1)

url = "/api/clusqmgr/resume/" + sys.argv[1] + '/' + sys.argv[2];

try:
	conn = httplib.HTTPConnection('localhost', 8081)
	conn.request('GET', url)
	res = conn.getresponse()
	result = json.loads(res.read())

	if 'error' in result:
		print ('Received a WebSphere MQ error: ' +	
			str(result['error']['reason']['code'])
		)
	else:
		print "Resume command succesfully send."

except httplib.HTTPException as e:
	print ('An HTTP error occurred while resuming the queuemanager in the cluster: ' +
		e.errno + e.strerror
	)
except socket.error as e:
	print e.strerror
	print 'Is the MQWeb daemon running?'
Suspend
'''
 Supends a queuemanager in a cluster 
 MQWeb runs on localhost and is listening on port 8081. 
'''
import sys
import json
import httplib
import socket

if len(sys.argv) < 3 :
	print 'Please pass me the name of a queuemanager and a clustername as argument'
	sys.exit(1)

url = "/api/clusqmgr/suspend/" + sys.argv[1] + '/' + sys.argv[2];

try:
	conn = httplib.HTTPConnection('localhost', 8081)
	conn.request('GET', url)
	res = conn.getresponse()
	result = json.loads(res.read())

	if 'error' in result:
		print ('Received a WebSphere MQ error: ' +	
			str(result['error']['reason']['code'])
		)
	else:
		print "Suspend command succesfully send."

except httplib.HTTPException as e:
	print ('An HTTP error occurred while suspending the queuemanager in the cluster: ' +
		e.errno + e.strerror
	)
except socket.error as e:
	print e.strerror
	print 'Is the MQWeb daemon running?'

Connection

Inquire
'''
 Inquire all connections from a queuemanager.
 MQWeb runs on localhost and is listening on port 8081. 
'''
import sys
import json
import httplib
import socket

if len(sys.argv) < 2 :
	print 'Please pass me the name of a queuemanager as argument'
	sys.exit(1)

url = '/api/conn/inquire/' + sys.argv[1]

try:
	conn = httplib.HTTPConnection('localhost', 8081)
	conn.request('GET', url)
	res = conn.getresponse()
	result = json.loads(res.read())

	if 'error' in result:
		print ('Received a WebSphere MQ error: ' +	
			str(result['error']['reason']['code'])
		)
	else:
		if len(result['data']) == 0:
			print "No connections found"
		else:
			for data in result['data']:
				print (data['ApplTag']['value'] + ': ' 
					+ data['ApplType']['text']
				)
except httplib.HTTPException as e:
	print ('An HTTP error occurred while inquiring connections: ' +
		e.errno + e.strerror
	)
except socket.error as e:
	print e.strerror
	print 'Is the MQWeb daemon running?'

Event Messages

Event
'''
 This sample will read all event messages from queue SYSTEM.ADMIN.CONFIG.EVENT
 and show all events that are related to queues.
 MQWeb runs on localhost and is listening on port 8081. 
'''

import sys
import json
import httplib
import socket

if len(sys.argv) < 2 :
	print 'Please pass me the name of a queuemanager as argument'
	sys.exit(1)

url = "/api/message/browse/" + sys.argv[1] + '/SYSTEM.ADMIN.CONFIG.EVENT'

try:
	conn = httplib.HTTPConnection('localhost', 8081)
	conn.request('GET', url)
	res = conn.getresponse()
	result = json.loads(res.read())

	if 'error' in result:
		print('Received a WebSphere MQ error: ' +	
			str(result['error']['reason']['code'])
		)
	else:
		for message in result['data']:
			if 'event' in message :
					#print(json.dumps(message, indent=2))
					if message['event']['ObjectType']['text'] == 'Queue' :
							print("MQ Command {0} generated a config event for {1}".format(
									message['event']['EventOrigin']['text'], 
									message['event']['QName']['value'])
							)
except httplib.HTTPException as e:
	print ('An HTTP error occurred while inquiring queuemanager: ' +
		e.errno + e.strerror
	)
except socket.error as e:
	print e.strerror
	print 'Is the MQWeb daemon running?'

Listeners

Inquire
'''
 Inquire all SYSTEM listeners with transporttype TCP from a queuemanager.
 MQWeb runs on localhost and is listening on port 8081. 
'''
import sys
import json
import httplib
import socket

if len(sys.argv) < 2 :
	print 'Please pass me the name of a queuemanager as argument'
	sys.exit(1)

url = '/api/listener/inquire/' + sys.argv[1] + '/SYSTEM*/TCP'

try:
	conn = httplib.HTTPConnection('localhost', 8081)
	conn.request('GET', url)
	res = conn.getresponse()
	result = json.loads(res.read())

	if 'error' in result:
		print ('Received a WebSphere MQ error: ' +	
			str(result['error']['reason']['code'])
		)
	else:
		if len(result['data']) == 0:
			print "No listeners found"
		else:
			for data in result['data']:
				print data['ListenerName']['value']
except httplib.HTTPException as e:
	print ('An HTTP error occurred while inquiring listeners: ' +
		e.errno + e.strerror
	)
except socket.error as e:
	print e.strerror
	print 'Is the MQWeb daemon running?'

Listener Statuses

Inquire
'''
 Inquire all listener statuses from a queuemanager.
 MQWeb runs on localhost and is listening on port 8081. 
'''
import sys
import json
import httplib
import socket

if len(sys.argv) < 2 :
	print 'Please pass me the name of a queuemanager as argument'
	sys.exit(1)

url = '/api/lsstatus/inquire/' + sys.argv[1]

try:
	conn = httplib.HTTPConnection('localhost', 8081)
	conn.request('GET', url)
	res = conn.getresponse()
	result = json.loads(res.read())

	if 'error' in result:
		print ('Received a WebSphere MQ error: ' +	
			str(result['error']['reason']['code'])
		)
	else:
		if len(result['data']) == 0:
			print "No listener status found"
		else:
			for data in result['data']:
				print ( data['ListenerName']['value'] +
					': ' + data['Status']['text']
				)
except httplib.HTTPException as e:
	print ('An HTTP error occurred while inquiring listener statuses: ' +
		e.errno + e.strerror
	)
except socket.error as e:
	print e.strerror
	print 'Is the MQWeb daemon running?'

Namelists

Inquire
'''
 This sample will show all SYSTEM namelists from a queuemanager with
 their description. MQWeb runs on localhost and is listening on port 8081. 
'''
import sys
import json
import httplib
import socket

if len(sys.argv) < 2 :
	print 'Please pass me the name of a queuemanager as argument'
	sys.exit(1)

url = '/api/nl/inquire/' + sys.argv[1] + '/SYSTEM*'

try:
	conn = httplib.HTTPConnection('localhost', 8081)
	conn.request('GET', url)
	res = conn.getresponse()
	result = json.loads(res.read())

	if 'error' in result:
		print ('Received a WebSphere MQ error: ' +	
			str(result['error']['reason']['code'])
		)
	else:
		if len(result['data']) == 0:
			print "No namelists found"
		else:
			for data in result['data']:
				print (data['NamelistName']['value'] + ': ' 
					+ data['NamelistDesc']['value']
				)
except httplib.HTTPException as e:
	print ('An HTTP error occurred while inquiring namelists: ' +
		e.errno + e.strerror
	)
except socket.error as e:
	print e.strerror
	print 'Is the MQWeb daemon running?'

Processes

Inquire
'''
 This sample will show all SYSTEM processes from a queuemanager with
 their description. MQWeb runs on localhost and is listening on port 8081. 
'''
import sys
import json
import httplib
import socket

if len(sys.argv) < 2 :
	print 'Please pass me the name of a queuemanager as argument'
	sys.exit(1)

url = '/api/process/inquire/' + sys.argv[1] + '/SYSTEM*'

try:
	conn = httplib.HTTPConnection('localhost', 8081)
	conn.request('GET', url)
	res = conn.getresponse()
	result = json.loads(res.read())

	if 'error' in result:
		print ('Received a WebSphere MQ error: ' +	
			str(result['error']['reason']['code'])
		)
	else:
		if len(result['data']) == 0:
			print "No processes found"
		else:
			for data in result['data']:
				print data['ProcessName']['value']
except httplib.HTTPException as e:
	print ('An HTTP error occurred while inquiring processes: ' +
		e.errno + e.strerror
	)
except socket.error as e:
	print e.strerror
	print 'Is the MQWeb daemon running?'

Queuemanager

Inquire
'''
 This sample will show the description of a queuemanager.
 MQWeb runs on localhost and is listening on port 8081. 
'''

import sys
import json
import httplib
import socket

if len(sys.argv) < 2 :
	print 'Please pass me the name of a queuemanager as argument'
	sys.exit(1)

url = "/api/qmgr/inquire/" + sys.argv[1]

try:
	conn = httplib.HTTPConnection('localhost', 8081)
	conn.request('GET', url)
	res = conn.getresponse()
	result = json.loads(res.read())

	if 'error' in result:
		print ('Received a WebSphere MQ error: ' +	
			str(result['error']['reason']['code'])
		)
	else:
		print (result['data'][0]['QMgrName']['value'] 
			+ ' : ' + result['data'][0]['QMgrDesc']['value']
		)
except httplib.HTTPException as e:
	print ('An HTTP error occurred while inquiring queuemanager: ' +
		e.errno + e.strerror
	)
except socket.error as e:
	print e.strerror
	print 'Is the MQWeb daemon running?'

Queuemanager Status

Inquire
'''
 This sample will show the startdate/time of a queuemanager.
 MQWeb runs on localhost and is listening on port 8081. 
'''

import sys
import json
import httplib
import socket

if len(sys.argv) < 2 :
	print 'Please pass me the name of a queuemanager as argument'
	sys.exit(1)

url = "/api/qmstatus/inquire/" + sys.argv[1]
input = {
	'QMStatusAttrs' : [
		'StartDate',
		'StartTime'
	]
}

try:
	headers = {
		'Content-Type': 'application/json'
	}
	conn = httplib.HTTPConnection('localhost', 8081)
	conn.request('POST', url, json.dumps(input), headers)
	res = conn.getresponse()
	result = json.loads(res.read())

	if 'error' in result:
		print ('Received a WebSphere MQ error: ' +	
			str(result['error']['reason']['code'])
		)
	else:
		print (result['data'][0]['QMgrName']['value'] 
			+ ' started on ' + result['data'][0]['StartDate']['value']
			+ ' ' + result['data'][0]['StartTime']['value']
		)
except httplib.HTTPException as e:
	print ('An HTTP error occurred while inquiring queuemanager status: ' +
		e.errno + e.strerror
	)
except socket.error as e:
	print e.strerror
	print 'Is the MQWeb daemon running?'

Queue

Inquire
'''
 This sample will show all SYSTEM queues from a queuemanager and
 prints the current queue depth if this property exists for the queue.
 MQWeb runs on localhost and is listening on port 8081. 
'''
import sys
import json
import httplib
import socket

if len(sys.argv) < 2 :
	print 'Please pass me the name of a queuemanager as argument'
	sys.exit(1)

url = "/api/queue/inquire/" + sys.argv[1] + "/SYSTEM*";

try:
	conn = httplib.HTTPConnection('localhost', 8081)
	conn.request('GET', url)
	res = conn.getresponse()
	result = json.loads(res.read())

	if 'error' in result:
		print ('Received a WebSphere MQ error: ' +	
			str(result['error']['reason']['code'])
		)
	else:
		for data in result['data']:
			line = data['QName']['value']
			if 'CurrentQDepth' in data:
				line += ': ' + str(data['CurrentQDepth']['value'])
			print line

except httplib.HTTPException as e:
	print ('An HTTP error occurred while inquiring queues: ' +
		e.errno + e.strerror
	)
except socket.error as e:
	print e.strerror
	print 'Is the MQWeb daemon running?'

Services

Inquire
'''
 This sample will show all services from a queuemanager.
 MQWeb runs on localhost and is listening on port 8081. 
'''
import sys
import json
import httplib
import socket

if len(sys.argv) < 2 :
	print 'Please pass me the name of a queuemanager as argument'
	sys.exit(1)

url = "/api/service/inquire/" + sys.argv[1];

try:
	conn = httplib.HTTPConnection('localhost', 8081)
	conn.request('GET', url)
	res = conn.getresponse()
	result = json.loads(res.read())

	if 'error' in result:
		print ('Received a WebSphere MQ error: ' +	
			str(result['error']['reason']['code'])
		)
	else:
		for data in result['data']:
			print data['ServiceName']['value']

except httplib.HTTPException as e:
	print ('An HTTP error occurred while inquiring topics: ' +
		e.errno + e.strerror
	)
except socket.error as e:
	print e.strerror
	print 'Is the MQWeb daemon running?'

Subscriptions

Inquire
'''
 This sample will show all subscriptions from a queuemanager.
 MQWeb runs on localhost and is listening on port 8081. 
'''
import sys
import json
import httplib
import socket

if len(sys.argv) < 2 :
	print 'Please pass me the name of a queuemanager as argument'
	sys.exit(1)

url = "/api/sub/inquire/" + sys.argv[1] + "/*";

try:
	conn = httplib.HTTPConnection('localhost', 8081)
	conn.request('GET', url)
	res = conn.getresponse()
	result = json.loads(res.read())

	if 'error' in result:
		print ('Received a WebSphere MQ error: ' +	
			str(result['error']['reason']['code'])
		)
	else:
		if len(result['data']) == 0:
			print "No subscriptions found"
		else:
			for data in result['data']:
				print data['SubName']['value']

except httplib.HTTPException as e:
	print ('An HTTP error occurred while inquiring subscriptions: ' +
		e.errno + e.strerror
	)
except socket.error as e:
	print e.strerror
	print 'Is the MQWeb daemon running?'

Subscription Statuses

Inquire
'''
 This sample will show all subscription statuses from a queuemanager.
 MQWeb runs on localhost and is listening on port 8081. 
'''
import sys
import json
import httplib
import socket

if len(sys.argv) < 2 :
	print 'Please pass me the name of a queuemanager as argument'
	sys.exit(1)

url = '/api/sbstatus/inquire/' + sys.argv[1]

try:
	conn = httplib.HTTPConnection('localhost', 8081)
	conn.request('GET', url)
	res = conn.getresponse()
	result = json.loads(res.read())

	if 'error' in result:
		print ('Received a WebSphere MQ error: ' +	
			str(result['error']['reason']['code'])
		)
	else:
		if len(result['data']) == 0:
			print "No substatus found"
		else:
			for data in result['data']:
				print data['SubName']['value']
except httplib.HTTPException as e:
	print ('An HTTP error occurred while inquiring sub statuses: ' +
		e.errno + e.strerror
	)
except socket.error as e:
	print e.strerror
	print 'Is the MQWeb daemon running?'

Topics

Inquire
'''
 This sample will show all topics from a queuemanager.
 MQWeb runs on localhost and is listening on port 8081. 
'''
import sys
import json
import httplib
import socket

if len(sys.argv) < 2 :
	print 'Please pass me the name of a queuemanager as argument'
	sys.exit(1)

url = "/api/topic/inquire/" + sys.argv[1] + "/SYSTEM*";

try:
	conn = httplib.HTTPConnection('localhost', 8081)
	conn.request('GET', url)
	res = conn.getresponse()
	result = json.loads(res.read())

	if 'error' in result:
		print ('Received a WebSphere MQ error: ' +	
			str(result['error']['reason']['code'])
		)
	else:
		for data in result['data']:
			print data['TopicName']['value']

except httplib.HTTPException as e:
	print ('An HTTP error occurred while inquiring topics: ' +
		e.errno + e.strerror
	)
except socket.error as e:
	print e.strerror
	print 'Is the MQWeb daemon running?'

Topic Statuses

Inquire
'''
 This sample will show all topic statuses from a queuemanager.
 MQWeb runs on localhost and is listening on port 8081. 
'''
import sys
import json
import httplib
import socket

if len(sys.argv) < 2 :
	print 'Please pass me the name of a queuemanager as argument'
	sys.exit(1)

url = '/api/tpstatus/inquire/' + sys.argv[1]

try:
	conn = httplib.HTTPConnection('localhost', 8081)
	conn.request('GET', url)
	res = conn.getresponse()
	result = json.loads(res.read())

	if 'error' in result:
		print ('Received a WebSphere MQ error: ' +	
			str(result['error']['reason']['code'])
		)
	else:
		if len(result['data']) == 0:
			print "No topicstatus found"
		else:
			for data in result['data']:
				print (data['TopicName']['value'] + ': ' 
					+ data['TopicStatus']['text']
				)
except httplib.HTTPException as e:
	print ('An HTTP error occurred while inquiring topic statuses: ' +
		e.errno + e.strerror
	)
except socket.error as e:
	print e.strerror
	print 'Is the MQWeb daemon running?'

Java

TODO!