We were getting KeyError for a given user who hasn't logged in a long
time and whose uid is bigger than the max uid in lastlog. Avoid this
by falling back to a value of 0 if the user is missing from lastlog.
realname = pwd.getpwnam(username).pw_gecos.decode('utf-8').split(',', 1)[0]
except:
realname = username
- lastlog_time = self.lastlog_times[username]
+ lastlog_time = self.lastlog_times.get(username, 0)
days_ago = int( (current_time - lastlog_time) / 3600 / 24 )
kwargs = {
'hostname': platform.node(),