Your IP : 172.28.240.42


Current Path : /usr/lib/python2.7/dist-packages/landscape/monitor/
Upload File :
Current File : //usr/lib/python2.7/dist-packages/landscape/monitor/computeruptime.pyc


Tc@sddlZddlmZddlZddlZddlmZddlmZddZde	fdYZ
d	e	fd
YZde	fdYZd
efdYZ
dS(iN(tdatetime(tto_timestamp(t
MonitorPluginu/proc/uptimecCs1t|dj}|j\}}t|S(s
    This parses a file in /proc/uptime format and returns a floating point
    version of the first value (the actual uptime).
    tr(tfiletreadlinetsplittfloat(tuptime_filetdatatuptidle((sD/usr/lib/python2.7/dist-packages/landscape/monitor/computeruptime.pyt
get_uptime
st	LoginInfocBseZdZdZdZRS(s=Information about a login session gathered from wtmp or utmp.thi32s4s32s256shhiiiiiii20scCstj|j|}|d|_|d|_|djd|_|djd|_|djd|_|djd|_	|d|_
|d	|_|d
|_t
j|d|_|d|_dS(
Niiitiiiiiii	i(tstructtunpackt
RAW_FORMATt
login_typetpidtstript
tty_devicetidtusernamethostnamettermination_statustexit_statust
session_idRtutcfromtimestampt
entry_timetremote_ip_address(tselftraw_datatinfo((sD/usr/lib/python2.7/dist-packages/landscape/monitor/computeruptime.pyt__init__s




(t__name__t
__module__t__doc__RR#(((sD/usr/lib/python2.7/dist-packages/landscape/monitor/computeruptime.pyR
stLoginInfoReadercBs)eZdZdZdZdZRS(swReader parses C{/var/log/wtmp} and/or C{/var/run/utmp} files.

    @file: Initialize the reader with an open file.
    cCs"||_tjtj|_dS(N(t_fileRtcalcsizeR
Rt_struct_length(R R((sD/usr/lib/python2.7/dist-packages/landscape/monitor/computeruptime.pyR#4s	ccs,x%tr'|j}|sPn|VqWdS(s2Returns a generator that yields LoginInfo objects.N(tTruet	read_next(R R"((sD/usr/lib/python2.7/dist-packages/landscape/monitor/computeruptime.pyt
login_info8s
	cCs>|jj|j}|r:t||jkr:t|SdS(s9Returns login data or None if no login data is available.N(R(treadR*tlenR
tNone(R R	((sD/usr/lib/python2.7/dist-packages/landscape/monitor/computeruptime.pyR,Bs
(R$R%R&R#R-R,(((sD/usr/lib/python2.7/dist-packages/landscape/monitor/computeruptime.pyR'.s		
t	BootTimescBs8eZdZdZddddZdZdZRS(s
/var/log/wtmpicCs||_||_||_dS(N(t	_filenamet_boots_newer_thant_shutdowns_newer_than(R tfilenametboots_newer_thantshutdowns_newer_than((sD/usr/lib/python2.7/dist-packages/landscape/monitor/computeruptime.pyR#Ps		cCsg}g}tt|j}|j|_|j|_x|jD]}|jj	drFt
|j}|jdkr||jkr|j
|||_q|jdkr||jkr|j
|||_qqFqFW||fS(Nt~treboottshutdown(R'RR2R3t
_last_bootR4t_last_shutdownR-Rt
startswithRRRtappend(R treboot_timestshutdown_timestreaderR"t	timestamp((sD/usr/lib/python2.7/dist-packages/landscape/monitor/computeruptime.pyt	get_timesVs"

cCs5|jdkr.ttjt|_n|jS(N(R;R0tintttimeR(R ((sD/usr/lib/python2.7/dist-packages/landscape/monitor/computeruptime.pytget_last_boot_timejsN(R$R%R0R;R<R#RCRF(((sD/usr/lib/python2.7/dist-packages/landscape/monitor/computeruptime.pyR1Ls	tComputerUptimecBsPeZdZdZdZddZdZedZedZ	dZ
RS(	s1Plugin reports information about computer uptime.scomputer-uptimetcomputers
/var/log/wtmpcCst|_||_dS(N(R+t
_first_runt
_wtmp_file(R t	wtmp_file((sD/usr/lib/python2.7/dist-packages/landscape/monitor/computeruptime.pyR#vs	cCsFtt|j||jjd|j|jd|jtdS(s7Register this plugin with the specified plugin manager.trunscomputer-uptimeN(tsuperRGtregistertreactortcall_onRLtcall_on_acceptedR+(R tregistry((sD/usr/lib/python2.7/dist-packages/landscape/monitor/computeruptime.pyRNzscCs|jj}|jrS|jd}tjj|rS|jd|j||qSntjj|jr|jd|j|j|ndS(sJCreate a message and put it on the message queue.

        The last logrotated file, if it exists, will be checked the
        first time the plugin runs.  This behaviour ensures we don't
        accidentally miss a reboot/shutdown event if the machine is
        rebooted and wtmp is logrotated before the client starts.
        s.1scomputer-uptimeN(	RRtbrokerRIRJtostpathtisfiletcall_if_acceptedtsend_message(R turgentRSR5((sD/usr/lib/python2.7/dist-packages/landscape/monitor/computeruptime.pyRLs	
	
cCsW|j|}d|ks'd|krSd|d<|jjj||jd|ndS(Nsshutdown-timess
startup-timesscomputer-uptimettypeRY(t_create_messageRRRSRXt_session_id(R R5RYtmessage((sD/usr/lib/python2.7/dist-packages/landscape/monitor/computeruptime.pyRXs

cCsi}g}g}|jjdd}|jjdd}t|d|d|}|j\}}|r|jjd|d||d<n|r|jjd|d||d<n|S(	s7Generate a message with new startup and shutdown times.slast-startup-timeislast-shutdown-timeR6R7is
startup-timessshutdown-times(t_persisttgetR1RCtset(R R5R]t
startup_timesR@tlast_startup_timetlast_shutdown_timettimes((sD/usr/lib/python2.7/dist-packages/landscape/monitor/computeruptime.pyR[s 		

(R$R%R&tpersist_nametscopeR#RNtFalseRLRXR[(((sD/usr/lib/python2.7/dist-packages/landscape/monitor/computeruptime.pyRGps	(RERRTRtlandscape.lib.timestampRtlandscape.monitor.pluginRRtobjectR
R'R1RG(((sD/usr/lib/python2.7/dist-packages/landscape/monitor/computeruptime.pyt<module>s
$