コンテンツにスキップ

WinActor実行サンプル[状態ファイル判断]

robosteinでWinActorの実行を制御、管理する場合のサンプルフローです。
制御は状態ファイルを用いて判断する方式になります。

サンプルフロー


[{"id":"d86ea55b.a12008","type":"clagent-run","z":"93959c56.16899","name":"PowerShell実行","command":"exec","listout":"payload","listoutType":"msg","statout":"payload","statoutType":"msg","getfilename":"","getfilenameType":"str","getfileout":"","getfileoutType":"msg","getfilebytes":false,"putfilein":"","putfileinType":"bin","putfilename":"","putfilenameType":"str","putfileout":"","putfileoutType":"msg","execps":"powershell","execpsType":"msg","execout":"payload","execoutType":"msg","execonconsole":true,"rpaproduct":"","rpaproductType":"str","rpaout":"","rpaoutType":"msg","target":"hostId","targetType":"msg","x":640,"y":280,"wires":[["ad31bdea.e9465"]]},{"id":"4242fac6.80fe84","type":"clagent-psbuild","z":"93959c56.16899","name":"WinActor実行スクリプト","template":"","scripts":"# ファイルパスを指定します\n# $file_path = 'C:\\\\Program Files (x86)\\\\WinActor\\\\WinActor.exe'\n$file_path = '${msg.winactorExePath}'\n\n\n# 引数を指定します(-f [対象ums5ファイル] -r -e)\n# $arg = '-f C:\\\\Users\\\\Administrator\\\\Desktop\\\\rs_demo\\\\WinActor\\\\winactor_demo_simple.ums5 -r -e'\n$arg = '-f ${msg.winactorScenarioPath} -r -e'\n\n# WinActorを起動します\n# $proc = Start-Process $file_path $arg -PassThru\nStart-Process $file_path $arg -PassThru\n","scriptsout":"powershell","scriptsoutType":"msg","append":false,"x":390,"y":280,"wires":[["d86ea55b.a12008"]]},{"id":"b3d98c54.3764","type":"inject","z":"93959c56.16899","name":"WinActor実行","topic":"","payload":"","payloadType":"date","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":150,"y":160,"wires":[["53c3dbbf.6a5764"]]},{"id":"f50c714c.cf04f","type":"clagent-run","z":"93959c56.16899","name":"ファイル取得実行","command":"getfile","listout":"payload","listoutType":"msg","statout":"payload","statoutType":"msg","getfilename":"statusLogPath","getfilenameType":"msg","getfileout":"payload","getfileoutType":"msg","getfilebytes":true,"putfilein":"","putfileinType":"bin","putfilename":"","putfilenameType":"str","putfileout":"","putfileoutType":"msg","execps":"powershell","execpsType":"msg","execout":"payload","execoutType":"msg","execonconsole":false,"rpaproduct":"","rpaproductType":"str","rpaout":"","rpaoutType":"msg","target":"hostId","targetType":"msg","x":630,"y":360,"wires":[["32677fb3.d9f5b"]]},{"id":"9f8e343e.3a9bf8","type":"corobo-trigger","z":"93959c56.16899","name":"正常終了","status":"1","statusType":"num","x":560,"y":540,"wires":[]},{"id":"32677fb3.d9f5b","type":"converter","z":"93959c56.16899","name":"SJISデータに変換","from":"sjis","x":870,"y":360,"wires":[["f79f14b4.f47468"]]},{"id":"f79f14b4.f47468","type":"switch","z":"93959c56.16899","name":"ステータス判断","property":"payload","propertyType":"msg","rules":[{"t":"regex","v":"START","vt":"str","case":false},{"t":"regex","v":"END","vt":"str","case":false},{"t":"regex","v":"ERROR","vt":"str","case":false}],"checkall":"true","repair":false,"outputs":3,"x":360,"y":540,"wires":[["d567680.c133c98"],["9f8e343e.3a9bf8"],["78745b3a.795174"]]},{"id":"78745b3a.795174","type":"corobo-trigger","z":"93959c56.16899","name":"エラー","status":"2","statusType":"num","x":550,"y":580,"wires":[]},{"id":"55c38b92.858c74","type":"delay","z":"93959c56.16899","name":"10秒待機","pauseType":"delay","timeout":"10","timeoutUnits":"seconds","rate":"1","nbRateUnits":"1","rateUnits":"second","randomFirst":"1","randomLast":"5","randomUnits":"seconds","drop":false,"x":1020,"y":480,"wires":[["f50c714c.cf04f"]]},{"id":"71e6456.4c25fbc","type":"function","z":"93959c56.16899","name":"ループ初期化","func":"msg.loopcount = 0\nreturn msg;","outputs":1,"noerr":0,"x":360,"y":360,"wires":[["f50c714c.cf04f"]]},{"id":"2db02aff.ae2876","type":"function","z":"93959c56.16899","name":"カウントアップ","func":"msg.loopcount = msg.loopcount + 1\nreturn msg;","outputs":1,"noerr":0,"x":820,"y":480,"wires":[["55c38b92.858c74"]]},{"id":"d567680.c133c98","type":"switch","z":"93959c56.16899","name":"ステータス判断","property":"loopcount","propertyType":"msg","rules":[{"t":"lt","v":"10","vt":"str"},{"t":"gte","v":"10","vt":"str"}],"checkall":"true","repair":false,"outputs":2,"x":580,"y":500,"wires":[["2db02aff.ae2876"],["d1cf0751.cd3c28"]]},{"id":"d1cf0751.cd3c28","type":"corobo-trigger","z":"93959c56.16899","name":"時間待エラー","status":"2","statusType":"num","x":820,"y":520,"wires":[]},{"id":"ad31bdea.e9465","type":"delay","z":"93959c56.16899","name":"5秒待機","pauseType":"delay","timeout":"5","timeoutUnits":"seconds","rate":"1","nbRateUnits":"1","rateUnits":"second","randomFirst":"1","randomLast":"5","randomUnits":"seconds","drop":false,"x":840,"y":280,"wires":[["71e6456.4c25fbc"]]},{"id":"37f41d47.b994d2","type":"clagent-psbuild","z":"93959c56.16899","name":"状態ログファイルを作成","template":"","scripts":"$statusLogPath = '${msg.statusLogPath}'\nSet-Content -Force -path $statusLogPath -value 'START'","scriptsout":"powershell","scriptsoutType":"msg","append":false,"x":390,"y":220,"wires":[["7c6e02f1.89116c"]]},{"id":"7c6e02f1.89116c","type":"clagent-run","z":"93959c56.16899","name":"PowerShell実行","command":"exec","listout":"payload","listoutType":"msg","statout":"payload","statoutType":"msg","getfilename":"","getfilenameType":"str","getfileout":"","getfileoutType":"msg","getfilebytes":false,"putfilein":"","putfileinType":"bin","putfilename":"","putfilenameType":"str","putfileout":"","putfileoutType":"msg","execps":"powershell","execpsType":"msg","execout":"payload","execoutType":"msg","execonconsole":true,"rpaproduct":"","rpaproductType":"str","rpaout":"","rpaoutType":"msg","target":"hostId","targetType":"msg","x":640,"y":220,"wires":[["4242fac6.80fe84"]]},{"id":"b2dd882.6497e78","type":"slack-webapi","z":"93959c56.16899","name":"","token":"cf875b9d.5cf608","channel":"CJMLKF2KG","channelType":"str","class":"postMessage","posttext":"WinActorが止まってます!","posttextType":"str","posticon":":robostein:","posticonType":"str","attachments":"","attachmentsType":"str","file":"screenshot","fileType":"str","filename":"SS","filenameType":"str","filetype":"auto","filetypeType":"str","filecomment":"先ほど取得したスクリーンショットです。","filecommentType":"str","x":800,"y":560,"wires":[]},{"id":"53c3dbbf.6a5764","type":"change","z":"93959c56.16899","name":"各種ファイルパスを設定","rules":[{"t":"set","p":"hostId","pt":"msg","to":"","tot":"str"},{"t":"set","p":"winactorExePath","pt":"msg","to":"C:\\\\Program Files (x86)\\\\WinActor\\\\WinActor.exe","tot":"str"},{"t":"set","p":"winactorScenarioPath","pt":"msg","to":"C:\\\\Users\\\\Administrator\\\\Desktop\\\\rs_demo\\\\WinActor\\\\winactor_demo_simple.ums5","tot":"str"},{"t":"set","p":"statusLogPath","pt":"msg","to":"C:\\\\Users\\\\Administrator\\\\Desktop\\\\rs_demo\\\\WinActor\\\\winactor_demo_simple.status","tot":"str"}],"action":"","property":"","from":"","to":"","reg":false,"x":390,"y":160,"wires":[["37f41d47.b994d2"]]},{"id":"c9419299.2c631","type":"e-mail","z":"93959c56.16899","server":"smtp.gmail.com","port":"465","secure":true,"tls":true,"name":"","dname":"","x":790,"y":600,"wires":[]},{"id":"6a313b5d.ccab64","type":"schedule","z":"93959c56.16899","name":"","triggers":[],"periods":[],"x":150,"y":200,"wires":[[]]},{"id":"c08c7ac8.3878c8","type":"comment","z":"93959c56.16899","name":"WinActor実行サンプルフロー[状態ファイル判断]","info":"各種ファイルパスには以下をいれてください\nhostid=実行ホストのID(エージェントID)\nwinactorExePath=winactorの実行(exe)ファイルパス\nwinactorScenarioPath=winactorのシナリオ(ums6など)のファイルパス\nstatusLogPath=状態を判断するためのログのファイルパス\n\n※状態ログファイル中の[START][END][ERROR]の\n文字列をみてステータス判断をするサンプルになります。","x":240,"y":80,"wires":[]},{"id":"cf875b9d.5cf608","type":"slack-oauthtoken","z":"","name":"demorobostein","token":"xoxb-131648894068-651731749953-rjuoQNUp0noPn6DFnFd4cQXF"}]

上記を設置すると以下のようなフローが表示されます。 winactorノード

解説

このサンプルフローの場合、状態ファイルというものをシナリオの中で書き出す必要があります。
従って既存のシナリオに手をくわえる必要がありますが、メリットとしては細かい状態を追えるためエラーのハンドリングがしやすくなります。
なお、シナリオに手をくわえる事が出来ない場合などは[プロセス]を見て判断する様なサンプルフローも用意していますのでそちらをご参考ください。

設定

各種ファイルパスには以下をいれてください

  • hostid=実行ホストのID(エージェントID)
  • winactorExePath=winactorの実行(exe)ファイルパス
  • winactorScenarioPath=winactorのシナリオ(ums6など)のファイルパス
  • statusLogPath=状態を判断するためのログのファイルパス

状態ログファイルの出力内容

状態ログファイル中の[START][END][ERROR]の文字列をみてステータス判断をするサンプルになりますので
このまま利用する場合は状態ファイルに上記文字を検知したいタイミングで出力する必要があります。

トリガーと出力

サンプルフローには、紐ついていない「スケジュール」ノードや「Slack送信」ノードなども置いてあります。
トリガーとして手動ではなくスケジュール実行させたい場合や、実行結果をSlackやメールなどに送信する場合に利用してください。

デバッグノード

サンプルフローにはデバッグノードを設置していません。
動作を確認する際にはデバッグノードを好きな位置に設置し、デバッグ表示をしつつ動作の確認をしてください。

これを使って

このサンプルフローを参考にし、

  • Winactorの実行管理

など、パーツとしての利用やフロー作成の参考にしてください。