Skip to content

admin ssh sometimes does coloured output (and/or forcibly open a pty) #8046

@calestyo

Description

@calestyo

Hey.

I'm writing this Prometheus exporter... and one thing I need to do for it is map domains to hostnames (i.e which domain runs on which host).
This information doesn't seem to be available (yet) via REST so I need to get it via admin SSH.

Problem there is (and I use Python Paramiko for the SSH connection), even when I re-use the same SSH connection (and just re-send new commands, i.e. handshake/auth/etc. is only done once)… when I do e.g. \s System@someDomain get hostname one by one for each domain, it's super slow, like in showstopper slow ... even for our few 100 domains at the LMU dCache it takes 4-5 mins.

So as a workaround I do:

\s System@someDomain,System@someOtherDomain,… get hostname

which is way faster...

The output there looks like:

System@storagesystem2:
    lcg-lrz-dc51.grid.lrz.de
System@storagesystem1:
    lcg-lrz-dc50.grid.lrz.de

which I can parse.


Problem now is, that sometimes, but not always (it seems randomly) dCache uses terminal escape sequences around the cell@domain lines.

I did quite some extensive testing... e.g. using Paramiko against OpenSSH server (whether it spuriously requests a PTY) but it seems that dCache's SSH is the cause, e.g. I can already reproduce it via repeated calls to ssh:

root@lcg-lrz-dcache0:~# ssh -p 59999   admin@localhost '\s System@storagesystem2,System@storagesystem1 get hostname' | hd
00000000  53 79 73 74 65 6d 40 73  74 6f 72 61 67 65 73 79  |System@storagesy|
00000010  73 74 65 6d 32 3a 0d 0a  20 20 20 20 6c 63 67 2d  |stem2:..    lcg-|
00000020  6c 72 7a 2d 64 63 35 31  2e 67 72 69 64 2e 6c 72  |lrz-dc51.grid.lr|
00000030  7a 2e 64 65 0d 0a 53 79  73 74 65 6d 40 73 74 6f  |z.de..System@sto|
00000040  72 61 67 65 73 79 73 74  65 6d 31 3a 0d 0a 20 20  |ragesystem1:..  |
00000050  20 20 6c 63 67 2d 6c 72  7a 2d 64 63 35 30 2e 67  |  lcg-lrz-dc50.g|
00000060  72 69 64 2e 6c 72 7a 2e  64 65 0d 0a 0d 0a        |rid.lrz.de....|
0000006e
root@lcg-lrz-dcache0:~# ssh -p 59999   admin@localhost '\s System@storagesystem2,System@storagesystem1 get hostname' | hd
00000000  1b 5b 31 6d 53 79 73 74  65 6d 40 73 74 6f 72 61  |.[1mSystem@stora|
00000010  67 65 73 79 73 74 65 6d  32 1b 5b 32 32 6d 3a 0d  |gesystem2.[22m:.|
00000020  0a 20 20 20 20 6c 63 67  2d 6c 72 7a 2d 64 63 35  |.    lcg-lrz-dc5|
00000030  31 2e 67 72 69 64 2e 6c  72 7a 2e 64 65 0d 0a 1b  |1.grid.lrz.de...|
00000040  5b 31 6d 53 79 73 74 65  6d 40 73 74 6f 72 61 67  |[1mSystem@storag|
00000050  65 73 79 73 74 65 6d 31  1b 5b 32 32 6d 3a 0d 0a  |esystem1.[22m:..|
00000060  20 20 20 20 6c 63 67 2d  6c 72 7a 2d 64 63 35 30  |    lcg-lrz-dc50|
00000070  2e 67 72 69 64 2e 6c 72  7a 2e 64 65 0d 0a 0d 0a  |.grid.lrz.de....|
00000080

My dCache is 11.2.0.

Could you possibly check whether this can be fixed (to never use colours if there's no tty requested by the client)?
Ideally with backports to all supported dCache versions, so that I can remove the special handling of this in my code.

Thanks :-)

Chris.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions