blob: fcfffbb3b8efd9d9d1a3fd307ae938b3d9a08556 [file] [log] [blame]
sv764t8bf49982018-10-25 01:42:52 -04001*** 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
4Library SSHLibrary
5Library 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.
14 [Arguments] ${HOST} ${user} ${pvt} ${password}= ${alias}=${HOST} ${timeout}=120s
15 Open Connection ${HOST} alias=${alias} timeout=${timeout}
16 Login With Public Key ${user} ${pvt} password=${password} delay=0.5 seconds
17
18Grep Local File
19 [Documentation] Grep the passed file name and return all of the lines that match the passed pattern using the current connection
20 [Arguments] ${pattern} ${fullpath}
21 ${output}= Execute Command grep ${pattern} ${fullpath}
22 [Return] ${output}
23
24 Grep File on Host
25 [Documentation] Grep the passed file name and return all of the lines that match the passed pattern using passed connection alias/host
26 [Arguments] ${host} ${pattern} ${fullpath}
27 Switch Connection ${host}
28 ${output}= Grep Local File ${pattern} ${fullpath}
29 @{lines}= Split To Lines ${output}
30 [Return] @{lines}
31
32Grep File on Hosts
33 [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}
35 &{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
43 [Documentation] Tail log file into grep which returns file lines containing the grep pattern. Will timeout after timeout= if expected pattern not received.
44 [Arguments] ${host} ${pattern} ${fullpath} ${expected} ${timeout}=60 ${options}=-c -0
45 Switch Connection ${host}
46 ${tailcommand}= Catenate tail ${options} -f ${fullpath} | grep --color=never ${pattern}
47 Write ${tailcommand}
48 ${stdout}= Read Until Regexp ${expected}
49 @{lines}= Split To Lines ${stdout}
50 [Return] @{lines}