blob: fcfffbb3b8efd9d9d1a3fd307ae938b3d9a08556 [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 HttpLibrary.HTTP
6Library String
7Library Collections
8
9*** Variables ***
10
11*** Keywords ***
12Open Connection And Log In
13 [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 -050014 [Arguments] ${HOST} ${user} ${pvt} ${password}= ${alias}=${HOST} ${timeout}=120s
DR695Hccff30b2017-02-17 18:44:24 -050015 Open Connection ${HOST} alias=${alias} timeout=${timeout}
16 Login With Public Key ${user} ${pvt} password=${password} delay=0.5 seconds
17
18Grep Local File
jf98603b22a2d2017-03-01 19:43:28 -050019 [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 -050020 [Arguments] ${pattern} ${fullpath}
jf98603b22a2d2017-03-01 19:43:28 -050021 ${output}= Execute Command grep ${pattern} ${fullpath}
DR695Hccff30b2017-02-17 18:44:24 -050022 [Return] ${output}
jf98603b22a2d2017-03-01 19:43:28 -050023
DR695Hccff30b2017-02-17 18:44:24 -050024 Grep File on Host
jf98603b22a2d2017-03-01 19:43:28 -050025 [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 -050026 [Arguments] ${host} ${pattern} ${fullpath}
27 Switch Connection ${host}
28 ${output}= Grep Local File ${pattern} ${fullpath}
jf98603b22a2d2017-03-01 19:43:28 -050029 @{lines}= Split To Lines ${output}
DR695Hccff30b2017-02-17 18:44:24 -050030 [Return] @{lines}
31
32Grep File on Hosts
jf98603b22a2d2017-03-01 19:43:28 -050033 [Documentation] Grep the passed file name and return all of the lines that match the passed pattern using passed list of connections
34 [Arguments] ${HOSTS} ${pattern} ${fullpath}
DR695Hccff30b2017-02-17 18:44:24 -050035 &{map}= Create Dictionary
36 :FOR ${HOST} IN @{HOSTS}
37 \ Log ${HOST}
38 \ @{lines}= Grep File on Host ${HOST} ${pattern} ${fullpath}
39 \ &{map}= Create Dictionary ${HOST}=@{lines} &{map}
40 [Return] &{map}
41
42Tail File on Host Until
jf98603b22a2d2017-03-01 19:43:28 -050043 [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 -050044 [Arguments] ${host} ${pattern} ${fullpath} ${expected} ${timeout}=60 ${options}=-c -0
45 Switch Connection ${host}
jf98603b22a2d2017-03-01 19:43:28 -050046 ${tailcommand}= Catenate tail ${options} -f ${fullpath} | grep --color=never ${pattern}
DR695Hccff30b2017-02-17 18:44:24 -050047 Write ${tailcommand}
jf98603b22a2d2017-03-01 19:43:28 -050048 ${stdout}= Read Until Regexp ${expected}
DR695Hccff30b2017-02-17 18:44:24 -050049 @{lines}= Split To Lines ${stdout}
50 [Return] @{lines}