blob: e89e5989de2ef558cb1ea92cdc40cf219f398d49 [file] [log] [blame]
DR695Hccff30b2017-02-17 18:44:24 -05001*** Settings ***
2Documentation Some handy Keywords for accessing log files over SSH. Assumptions are that logs will belong to users other than the currently logged in user and that sudo will be required
3Library OperatingSystem
jf98603b22a2d2017-03-01 19:43:28 -05004Library SSHLibrary
DR695Hccff30b2017-02-17 18:44:24 -05005Library String
6Library Collections
7
DR695Hccff30b2017-02-17 18:44:24 -05008*** Keywords ***
9Open Connection And Log In
10 [Documentation] Open a connection using the passed user and SSH key. Connection alias will be the host name by default.
jf98603b22a2d2017-03-01 19:43:28 -050011 [Arguments] ${HOST} ${user} ${pvt} ${password}= ${alias}=${HOST} ${timeout}=120s
DR695Hccff30b2017-02-17 18:44:24 -050012 Open Connection ${HOST} alias=${alias} timeout=${timeout}
13 Login With Public Key ${user} ${pvt} password=${password} delay=0.5 seconds
14
15Grep Local File
jf98603b22a2d2017-03-01 19:43:28 -050016 [Documentation] Grep the passed file name and return all of the lines that match the passed pattern using the current connection
DR695Hccff30b2017-02-17 18:44:24 -050017 [Arguments] ${pattern} ${fullpath}
jf98603b22a2d2017-03-01 19:43:28 -050018 ${output}= Execute Command grep ${pattern} ${fullpath}
DR695Hccff30b2017-02-17 18:44:24 -050019 [Return] ${output}
jf98603b22a2d2017-03-01 19:43:28 -050020
DR695H67afaca2019-07-23 17:13:23 -040021Grep File on Host
jf98603b22a2d2017-03-01 19:43:28 -050022 [Documentation] Grep the passed file name and return all of the lines that match the passed pattern using passed connection alias/host
DR695Hccff30b2017-02-17 18:44:24 -050023 [Arguments] ${host} ${pattern} ${fullpath}
24 Switch Connection ${host}
25 ${output}= Grep Local File ${pattern} ${fullpath}
jf98603b22a2d2017-03-01 19:43:28 -050026 @{lines}= Split To Lines ${output}
DR695Hccff30b2017-02-17 18:44:24 -050027 [Return] @{lines}
28
29Grep File on Hosts
jf98603b22a2d2017-03-01 19:43:28 -050030 [Documentation] Grep the passed file name and return all of the lines that match the passed pattern using passed list of connections
31 [Arguments] ${HOSTS} ${pattern} ${fullpath}
DR695Hccff30b2017-02-17 18:44:24 -050032 &{map}= Create Dictionary
33 :FOR ${HOST} IN @{HOSTS}
34 \ Log ${HOST}
35 \ @{lines}= Grep File on Host ${HOST} ${pattern} ${fullpath}
36 \ &{map}= Create Dictionary ${HOST}=@{lines} &{map}
37 [Return] &{map}
38
39Tail File on Host Until
jf98603b22a2d2017-03-01 19:43:28 -050040 [Documentation] Tail log file into grep which returns file lines containing the grep pattern. Will timeout after timeout= if expected pattern not received.
DR695Hccff30b2017-02-17 18:44:24 -050041 [Arguments] ${host} ${pattern} ${fullpath} ${expected} ${timeout}=60 ${options}=-c -0
42 Switch Connection ${host}
jf98603b22a2d2017-03-01 19:43:28 -050043 ${tailcommand}= Catenate tail ${options} -f ${fullpath} | grep --color=never ${pattern}
DR695Hccff30b2017-02-17 18:44:24 -050044 Write ${tailcommand}
jf98603b22a2d2017-03-01 19:43:28 -050045 ${stdout}= Read Until Regexp ${expected}
DR695Hccff30b2017-02-17 18:44:24 -050046 @{lines}= Split To Lines ${stdout}
47 [Return] @{lines}