"Last time seen" - when was the last contact between minion and master?

604 views
Skip to first unread message

Markus Kramer

unread,
May 21, 2015, 7:25:19 AM5/21/15
to salt-...@googlegroups.com
I think Minions regularly try to contact the master.
I believe this is just "I am here" message, but I might be wrong.

I think these are the messages I see in the output of `salt-master -l info`:
[INFO    ] Clear payload received with command _auth
[INFO    ] Authentication request from Mini01
[INFO    ] Authentication accepted from Mini01



I would like to query date and time of the last contact for all minions the salt-master has a key.

Format of the query result:
| Minion | Last contact       |
| Mini01 | 2015-05-21--12:30
     |
| Mini02 | 2015-05-20--10:30     |


Thank you

Markus Kramer

unread,
May 22, 2015, 5:48:43 AM5/22/15
to salt-...@googlegroups.com

After reading how-do-i-list-all-connected-salt-stack-minions I wrote the below script.

The result is consistent with `salt-run manage.status`

While I seem to have my answer, the approach needs confirmation, e.g.:
 - how stable (across releases) are the file structures of /etc/salt/pki/master/minions and /var/cache/salt/master/minions ?
 - why manage.status waits 10 seconds? 
 - is "last-seen time older than 1 hour" equivalent to "up" and "down"?


Thank you





'''
GOAL
list 'last seen' time of minions

USAGE
sudo python ./halloMinion.py  | sort

COMPARE WITH
sudo salt-run manage.status

EXAMPLE OUTPUT
2015.05.18 10:36:43     Mini1
2015.05.21 13:56:08     Mini2
2015.05.21 23:25:54     Mini3
2015.05.22 10:51:22     Mini4
2015.05.22 10:56:56     Mini5

WARNING
reverse engineering, assumptions, needs offical comment.


'''
##########################################################################
import sys
from     os             import listdir
from     os.path import isfile
from     os.path import isdir
import datetime
import os
import os.path


##########################################################################
def modification_date(filename):
    t = os.path.getmtime(filename)
    x = datetime.datetime.fromtimestamp(t)
    return x

def datetime2string(i):
    r = i.strftime("%Y.%m.%d %H:%M:%S")
    return r


##########################################################################

DIR_OF_DIR_pki = '/etc/salt/pki/master/minions/'
'''
Only those Minons are known
'''



DIR_OF_DIR_cache = '/var/cache/salt/master/minions/'
'''
There are more directories than there are known minons
In each directory there are two files.
'''

##########################################################################

all_known_minions = [ f for f in listdir(DIR_OF_DIR_pki) if isdir(DIR_OF_DIR_pki) ]

for one_minion in all_known_minions:
    one_minion_cache_dir = os.path.join(DIR_OF_DIR_cache, one_minion)
    age_of_d = modification_date(os.path.join(one_minion_cache_dir, 'data.p'))
    age_of_m = modification_date(os.path.join(one_minion_cache_dir, 'mine.p'))
    lastseen = max(age_of_d,age_of_m)
    print datetime2string( lastseen)+ "\t" + one_minion



Colton Myers

unread,
May 28, 2015, 4:06:38 PM5/28/15
to salt-...@googlegroups.com
While I seem to have my answer, the approach needs confirmation, e.g.:
 - how stable (across releases) are the file structures of /etc/salt/pki/master/minions and /var/cache/salt/master/minions ?

What do you mean by "stable"? They don't get deleted with new releases, if that's what you're asking.
 
 - why manage.status waits 10 seconds? 

Because if there are any minions for which we have accepted keys, but that are not responding, we must wait for the command to timeout before we declare them as "disconnected".
 
 - is "last-seen time older than 1 hour" equivalent to "up" and "down"?

I suppose that depends on your definition of "up" and "down". We don't have an official time limit on "up" and "down" that I know of.

--
Colton Myers
Platform Engineer, SaltStack
@basepi on Twitter/Github/IRC 



--
You received this message because you are subscribed to the Google Groups "Salt-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to salt-users+...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Markus Kramer

unread,
May 29, 2015, 10:27:26 AM5/29/15
to salt-...@googlegroups.com


On Thursday, 28 May 2015 22:06:38 UTC+2, basepi wrote:
While I seem to have my answer, the approach needs confirmation, e.g.:
 - how stable (across releases) are the file structures of /etc/salt/pki/master/minions and /var/cache/salt/master/minions ?

What do you mean by "stable"? They don't get deleted with new releases, if that's what you're asking.

Then I kindly propose to integrate the above code as "verbose" option into salt.manage down.
For me it is useful to know how long a minion is down - "down" can be two hours or two weeks.

 

Colton Myers

unread,
Jun 4, 2015, 6:41:03 PM6/4/15
to salt-...@googlegroups.com
Perhaps a new function within that manage runner? We'd love to see a pull request.

--
Colton Myers
Platform Engineer, SaltStack
@basepi on Twitter/Github/IRC

markus...@posteo.de

unread,
Jun 6, 2015, 1:53:02 PM6/6/15
to salt-...@googlegroups.com, Colton Myers
Good - I then finally have a reason to understand how to do a pull request :-)
You received this message because you are subscribed to a topic in the Google Groups "Salt-users" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/salt-users/MBQJSiHHNSI/unsubscribe.
To unsubscribe from this group and all its topics, send an email to salt-users+...@googlegroups.com.

Colton Myers

unread,
Jun 11, 2015, 2:55:07 PM6/11/15
to markus...@posteo.de, salt-...@googlegroups.com

--
Colton Myers
Platform Engineer, SaltStack
@basepi on Twitter/Github/IRC
Reply all
Reply to author
Forward
0 new messages