ベースのURLでパラメーターをSQL Diagnostic Managerに渡すことにより、APIにアクセスできます。
例えば、SQL Diagnostic ManagerがIP 192.168.1.1のシステムで稼働している場合、パラメーターは次のURLに渡す必要があります:http://192.168.1.1:5555/
HTTPメソッドのGETとPOSTのいずれかを使用できます。
パラメーター
渡す必要があるパラメーターは次のとおりです:
- _object:これは、SQL Diagnostic Managerで基本的に要求の宛先を指定する論理オブジェクトを処理します。MONyogAPI以外の値は受け付けません。
 - _action:これは、先に指定したオブジェクトで、要求の宛先になるパートを指定します。指定できる値は次のとおりです:
- Alerts
 - DataCollection
 - Sniffer
 - LongRunningQueries
 - LockedQueries
 - LongRunningQueryAction
 - AddServer
 - EditServer
 - RemoveServer
 
 - _value:_actionフィールドで指定したアクションに実行する操作。指定できる値は、以下のとおりです:
- Alerts、DataCollection、Sniffer、LongRunningQueries、LockedQueries: enableとdisable
 - LongRunningQueryAction: notify、kill、notifyandkill
 
 - _user:Monyogユーザー、LDAPユーザー、または、LDAPグループユーザーを指定できます。ユーザーを指定しなければ、デフォルトでadminアカウントを使用します。
 - _password:specified _userのパスワード。
 - _server:操作が実行されるコンマ(‘,’)区切りのサーバーの名前またはデータディレクトリ数。
 - _tags:指定されたタグの下にあるすべてのサーバーに対して実行される操作のコンマ(‘,’)区切りのタグの名前。
 
サーバー管理のAPI
APIを用いてSQL Diagnostic Managerでサーバーを管理するためには、以下のパラメーターを渡す必要があります:
- _server:登録されるサーバーの名前とデータディレクトリ数
 - _mysqlhost:MySQLホスト/IPアドレス
 - _mysqluser:MySQLユーザー名
 - _mysqlport:MySQLポート
 - _mysqlpassword:MySQLユーザーパスワード
 
例えば、サーバーを追加するためには:
$ curl "192.168.1.1:5555/?_object=MONyogAPI&_action=addserver&_user=admin
       &_server=Production&_mysqlhost=127.0.0.1&_mysqluser=admin
       &_mysqlport=3306&_mysqlpassword=adminpassword"
サーバー登録用の追加パラメーターをここに一覧表示します。
例えば、Production001という名前のサーバーをSQL Diagnostic Managerに登録したとします。HTTP GETメソッドによるこのサーバーのデータ収集を停止する場合のURLは以下のとおりです:
$ curl “http://192.168.1.1:5555/?_object=MONyogAPI&_action=DataCollection
       &_value=disable&_password=mypassword&_server=Production001”
curlで使用できる各種URLを以下にまとめます:
<server name>のデータ収集を開始する
$ curl "http://192.168.1.1:5555/?_object=MONyogAPI&_action=DataCollection
       &_value=enable&_user=admin&_password=Password&_server=Production001"
<multiples servers>のデータ収集を開始する
$ curl "http://192.168.1.1:5555/?_object=MONyogAPI&_action=DataCollection
       &_value=enable&_user=admin&_password=Password&_server=Production001,Test"
<server name>(プロダクションのスレーブ)のデータ収集を終了する
$ curl "http://192.168.1.1:5555/?_object=MONyogAPI&_action=DataCollection
       &_value=disable&_user=admin&_password=Password&_server=Slave+Of+Production"
<tag>のデータ収集を開始する
$ curl "http://192.168.1.1:5555/?_object=MONyogAPI&_action=DataCollection
       &_value=enable&_user=admin&_password=Password&_tag=Production"
<tag>のデータ収集を終了する
$ curl "http://192.168.1.1:5555/?_object=MONyogAPI&_action=DataCollection
       &_value=disable&_user=admin&_password=Password&_tag=Production"
すべてのサーバーのデータ収集をグローバルに停止する(メンテナンス)
$ curl “http://192.168.1.1:5555/?_object=MONyogAPI&_action=datacollection&_value=disable&_user=admin&_password="
すべてのサーバーのデータ収集をグローバルに開始する(メンテナンス)
$ curl “http://192.168.1.1:5555/?_object=MONyogAPI&_action=datacollection&_value=enable&_user=admin&_password="
<server name>のアラートを有効にする
$ curl "http://192.168.1.1:5555/?_object=MONyogAPI&_action=Alerts
       &_value=enable&_user=admin&_password=Password&_server=Production001"
<server name>のアラートを無効にする
$ curl "http://192.168.1.1:5555/?_object=MONyogAPI&_action=Alerts
       &_value=disable&_user=admin&_password=Password&_server=Production001"
<tag>のアラートを有効にする
$ curl "http://192.168.1.1:5555/?_object=MONyogAPI&_action=Alerts
       &_value=enable&_user=admin&_password=Password&_tag=Production"
<tag>のアラートを無効にする
$ curl "http://192.168.1.1:5555/?_object=MONyogAPI&_action=Alerts
       &_value=disable&_user=admin&_password=Password&_tag=Production"
すべてのサーバーのアラートをグローバルに無効する(メンテナンス)
$ curl "http://192.168.1.1:5555/?_object=MONyogAPI&_action=Alerts&_value=disable&_user=admin&_password="
すべてのサーバーのアラートをグローバルに有効する(メンテナンス)
$ curl "http://192.168.1.1:5555/?_object=MONyogAPI&_action=Alerts&_value=enable&_user=admin&_password="
<server name>のスニッファーを有効にする
$ curl "http://192.168.1.1:5555/?_object=MONyogAPI&_action=sniffer
       &_value=enable&_server=Production001"
<server name>のスニッファーを無効にする
$ curl "http://192.168.1.1:5555/?_object=MONyogAPI&_action=sniffer
       &_value=disable&_server=Production001"
サーバーを追加する
$ curl "http://192.168.1.1:5555/?_object=MONyogAPI&_action=addserver
       &_mysqluser=msandbox&_mysqlhost=127.0.0.1&_mysqlport=3306&_tags=Production
       &_server=Test&_mysqlpassword=msandbox&_connectontype=direct
       &_user=admin&_password=Password"
SSHトンネル付きサーバーを追加する
$ curl "http://192.168.1.1:5555/?_object=MONyogAPI&_action=addserver
       &_mysqluser=msandbox&_mysqlhost=127.0.0.1&_mysqlport=3306
       &_tags=Production&_server=Test&_mysqlpassword=msandbox
       &_connectiontype=ssh&_sshhost=192.168.1.86&_sshuser=username
       &_sshpassword=sshpassword&_sshport=22&_user=admin&_password=Password"
サーバーを編集する
$ curl "http://192.168.1.1:5555/?_object=MONyogAPI&_action=editserver
       &_mysqluser=msandbox&_mysqlhost=127.0.0.1&_mysqlport=3306
       &_tags=Production&_server=Test&_mysqlpassword=msandbox
       &_connectontype=direct&_user=admin&_password=Password"
サーバーを削除する
$ curl "http://192.168.1.1:5555/?_object=MONyogAPI&_action=removeserver&_server=Test"
<tag>の下のすべてのサーバーを削除する
curl "http://192.168.1.1:5555/?_object=MONyogAPI&_action=removeserver&_tag=Production”
複数のサーバーを削除する
curl "http://192.168.1.1:5555/?_object=MONyogAPI&_action=removeserver&_server=Server1,Server2”
コードを返す
SQL Diagnostic Managerとの接続に成功すると、SQL Diagnostic Managerはテキストメッセージを返します。メッセージはJSON形式です:
{“STATUS”: “SUCCESS/FAILURE”, “RESPONSE” : “<Response text>”}
アプリケーションはこのメッセージを構文解析して、操作が成功したかどうかを判定します。
注意
バージョン5.21以降、_object=ConnectionMgrに対するAPIコールを非推奨にしました。代わりに、_object=MONyogAPIを使用してください。
アプリケーション
Monyog APIは、柔軟性に富み、Perl、VBScriptなどのスクリプト言語といった他のプログラミング言語からアクセスできます。以下に示したのは、コマンドラインから必要なパラメーターを承認し、指定されたアクションを実行する汎用性の高いPerlスクリプトです。
#! /usr/bin/perl
use LWP 5.64;
# USAGE: MONyog.pl <hostname>:<port> <user> <password> <connection_name/ID> <action> <value>
# $ARGV[0] = hostname:port of server running Monyog
# $ARGV[1] = Monyog user
# $ARGV[2] = Monyog password
# $ARGV[3] = connection name
# $ARGV[4] = action
# $ARGV[5] = value
my $numArgs = $#ARGV + 1;
if($numArgs < 5) {
   die 'USAGE: MONyog.pl <hostname>:<port> <user> <password> <connection_name/ID> <action>';
}
my $browser = LWP::UserAgent->new;
# The request URL
my $url = URI->new('http://' . $ARGV[0] . '/');
# The form data pairs:
$url->query_form(
   '_object' => 'MONyogAPI',
   '_action' => $ARGV[4],
   '_user' => $ARGV[1]
   '_password' => $ARGV[2],
   '_server' => $ARGV[3],
   '_value' => $ARGV[5]
);
# The response object
$response = $browser->post($url);
if (!$response->is_success) {# Error connecting to MONyog
   die $response->status_line . "\n";
} else { 
   # Successfully connected to MONyog; print MONyog's response
   print $response->content . "\n";
}
                  