Variable substitution for logged in user for action, possible?

I’d love to user the username of the person logged in, like what shows in the dashboard display inside of a url action … something like $USERNAME$ . Is there such a template variable available?

Found it! $USER_ID$ (is there anyway to find out stuff like this without a lot of searching?)

2 Likes

For what purpose do you need the currently logged in user?

Custom icon action for Windows hosts that integrates bringing up an RDP to the host, just wanted to fill in the user automatically.

1 Like

Wow that’s cool!

Can you share your solution ? To open RDP to the host that will be really very nice!

I wrote a cgi-bin program in bash (but you could do this in whatever language). Then setup an action (Global Settings -> Custom icon and actions) a show in column one… with something like:

https://somehost.example.com/cgi-bin/rdp?host=$HOSTNAME$&user=$USER_ID$

#!/bin/bash
# The cgi-bin/rdp program

# REQUEST_URI look like /cgi-bin/rdp?host=hostname&user=username

rdphost=`echo "$REQUEST_URI" | sed -n 's,.*[?&]host=\([A-Za-z0-9-][A-Za-z0-9-]*\).*,\1,p'`
rdpuser=`echo "$REQUEST_URI" | sed -n 's,.*[?&]user=\([A-Za-z0-9-][A-Za-z0-9-]*\).*,\1,p'`
rdpdomain=EXAMPLE
rdpfulldomain=example.com

if [ "$rdphost" ]; then
  cat <<HERE
Content-type: application/rdp
Content-disposition: attachment;filename=${rdphost}.rdp

redirectclipboard:i:1
redirectposdevices:i:0
redirectprinters:i:1
redirectcomports:i:1
full address:s:${rdphost}.${rdpfulldomain}
username:s:${rdpuser}
domain:s:${rdpdomain}
HERE
fi
3 Likes

Thank you so much @cjcox I’ll test that. :slight_smile:

Where did you upload the bash file? The path please

You’d put the script wherever you would normally put cgi programs on your web server. Btw, this does not have to reside on the checkmk server (ours doesn’t).

1 Like

Ah okay thanks for the note @cjcox