LoginSignup
0
1

More than 5 years have passed since last update.

Python - paramikoで Cisco Webex Devices を操作する

Last updated at Posted at 2018-12-29

Cisco Systems Japan Advent Calendar 2018
をみながら、私のフィールドのビデオ会議関連に何か役立てないかなと徒然書く企画の1回目です。

@radiantmarch さんの 第2回: ネットワーク自動化開発実践 - Python でルータを操作する を参考に、Python での Cisco Webex Devices の API である xAPI 操作を SSH 経由で考えてみます。通常、xAPI は HTTP POST で操作可能なので、オススメは REST ですが、社内セキュリティなどで Web サーバを Disable にする必要があり SSH でしか API を叩けないという想定となります。

Cisco Webex Devices を Python で操作する

paramiko をインストールします。ルータに接続してコマンドを実行する Python コードのうち、 send the command の部分を xAPI の書式に書き換えます。

# send the command
remote_shell.send("xstatus SystemUnit Software Version\n")
time.sleep(1)
output = remote_shell.recv(65535)
print(output)

出力結果はこんな感じでした。例えばこれを定期的にかけて、クラウド登録時にソフトウェアのバージョンアップがあれば知らせる、ということもできそうですね。

-------------------- 10.X.X.X  --------------------
b'Welcome to \r\nCisco Codec Release RoomOS 2018-12-06 7513bae968a\r\nSW Release Date: 2018-12-06\r\n*r Login successful\r\nOK\r\n\r\n'
b'xstatus SystemUnit Software Version\r\n*s SystemUnit Software Version: "ce9.7.0.7513bae968a"\r\n** end\r\n\r\nOK\r\n'

Python から自動発信

上記を少し改造して、通話状態をチェックし、通話がなければ自動発信させるスクリプトを考えてみます。

通話状態は Cisco Webex Devices xAPI コマンドでは

xstatus Call Status 

で取得できます。通話があるときはそのステータス、通話がないときはエラーが返ります。

xstatus Call Status 
*r Status (status=Error): 
*r Status Reason: "No match on address expression"
*r Status XPath: "Status/Call/Status"
** end

ERROR

強引ですが、status=Error が返り値に含まれていたら発信をするようにします。発信するコマンドは

xcommand Dial Number:発信先

です。

少し間を置きながら、こんな感じの書き方で動作を確認しました。

# send the command
remote_shell.send("xstatus Call Status\n")
time.sleep(1)
output = remote_shell.recv(65535)
time.sleep(2)
if 'status=Error' in output.decode():
    remote_shell.send("xcommand Dial Number: example@example.com\n")
    time.sleep(2)
    output = remote_shell.recv(65535)
    print(output)
else:
    print(output)

出力(通話成功)

-------------------- 10.X.X.X  --------------------
b'Cisco Codec Release ce 9.6.0 8ea7f63e365 2018-11-20\r\nSW Release Date: 2018-11-20\r\n*r Login successful\r\nOK\r\n\r\n'
b'xcommand Dial Number: example@example.com\r\n\r\nOK\r\n*r DialResult (status=OK): \r\n*r DialResult CallId: 21\r\n*r DialResult ConferenceId: 16\r\n** end\r\n'

出力(失敗)

端末の現状のステータスを出力、ここでは EarlyMedia を表示して終わり。

-------------------- 10.X.X.X  --------------------
b'Cisco Codec Release ce 9.6.0 8ea7f63e365 2018-11-20\r\nSW Release Date: 2018-11-20\r\n*r Login successful\r\nOK\r\n\r\n'
b'xstatus Call Status\r\n*s Call 22 Status: EarlyMedia\r\n** end\r\n\r\nOK\r\n'

Cisco Webex Devices で netmiko はできるのか?

netmiko は残念ながら Cisco Webex Devices xAPI に対応していません。
ただ、特権モードや Config モードなどの考え方がないので、単純な応答であれば上記の paramiko で頑張るのがよいかもしれません。

謝辞

@radiantmarch さん、素晴らしい投稿ありがとうございました。

0
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
1