HEX
Server: LiteSpeed
System: Linux altar46.supremepanel46.com 4.18.0-553.83.1.lve.el8.x86_64 #1 SMP Wed Nov 12 10:04:12 UTC 2025 x86_64
User: jysa (4021)
PHP: 8.3.31
Disabled: NONE
Upload Files
File: //lib/python2.7/site-packages/pynag/Utils/misc.pyc
�
�O�]c@@s�dZddlmZddlZddlZddlZddlZddlZddl	Zddl
Z
ddlmZddl
mZdefd��YZdefd	��YZd
efd��YZdZdS(
s� miscellaneous utils classes and function.

 The reason they don't live in in pynag.Utils is that they have more requirements, and they do on occation import
 pynag.Model og pynag.Parsers
i(tabsolute_importN(t
PynagError(t	bytes2strt	MiscErrorcB@seZdZRS(s%Base class for errors in this module.(t__name__t
__module__t__doc__(((s4/usr/lib/python2.7/site-packages/pynag/Utils/misc.pyRstSandboxErrorcB@seZdZRS(sFRaised when FakeEnvironment tries to modify files outside its sandbox.(RRR(((s4/usr/lib/python2.7/site-packages/pynag/Utils/misc.pyRstFakeNagiosEnvironmentcB@s�eZdZdded�Zd�Zd�Zd�Zd�Z	d�Z
d�Zd�Zd	�Z
dd
d�Zdd�Zd
�Zd�Zd�Zd�Zd�ZRS(s� Creates a fake nagios environment with minimal configs in /tmp/

    Example:
        >>> nagios = FakeNagiosEnvironment()
        >>> nagios.create_minimal_environment()  # Create temporary director with minimal config
        >>> nagios.update_model()  # Update the global variables in pynag.Model
        >>> nagios.configure_livestatus()  # Configure a livestatus socket
        >>> result, stdout, stderr = nagios.start()  # Start up nagios
        >>> config = nagios.get_config()   # Returns config_parser.Config instance
        >>> livestatus = nagios.get_livestatus()  # Returns livestatus.Livestatus instance
        >>> result, stdout, sdterr = nagios.stop()  # Stop nagios
        >>> nagios.terminate()  # Stops nagios and cleans up everything

    cC@sm||_||_t|_||_d|_d|_tj	d�|_
tjj
|j
d�}||_dS(Nsnagios-environmentslivestatus.socket(tglobal_config_filetp1_filetFalset_model_is_dirtytlivestatus_module_pathtNonetlivestatus_objecttconfigttempfiletmkdtempttempdirtostpathtjointlivestatus_socket_path(tselfR	R
t
livestatustpath_to_socket((s4/usr/lib/python2.7/site-packages/pynag/Utils/misc.pyt__init__0s						cC@s|js|j�n|jS(N(Rtcreate_minimal_environment(R((s4/usr/lib/python2.7/site-packages/pynag/Utils/misc.pyt
get_config<s	
cC@s|js|j�n|jS(N(Rtconfigure_livestatus(R((s4/usr/lib/python2.7/site-packages/pynag/Utils/misc.pytget_livestatusAs	
cC@sytjj|_tjj|_tjj|_|j�tj_|jjtj_|j	tj_gtj_
t|_dS(sC Update the global variables in pynag.Model to point to our config N(
tpynagtModeltpynag_directorytoriginal_objects_dirtcfg_filetoriginal_cfg_fileRtoriginal_configRtobjects_dirt
eventhandlerstTrueR(R((s4/usr/lib/python2.7/site-packages/pynag/Utils/misc.pytupdate_modelFsc@s.��fd�}�j|_�j|_|S(s� Safety decorator aroundaround self.config.open()

         It wraps around self.config.open() and raises error if the fake
         nagios environment tries to open file outside the sandbox.
        c@s9|j�j�r"�|||�Std|f��dS(Ns@FakeNagiosEnvironment tried to open file outside its sandbox: %s(t
startswithRR(tfilenametargstkwargs(tfuncR(s4/usr/lib/python2.7/site-packages/pynag/Utils/misc.pytwrapYs(RR(RR/R0((R/Rs4/usr/lib/python2.7/site-packages/pynag/Utils/misc.pytopen_decoratorSscC@s:|jtj_|jtj_|jtj_t|_	dS(s. Restores the global variables in pynag.Model N(
R&R R!RR%R$R#R"RR(R((s4/usr/lib/python2.7/site-packages/pynag/Utils/misc.pyt
restore_modelbsc	C@s(|j}tjj|d�}|_t|d�jd�tjj|d�}|_tj|�tjj|jd�}tj|�tjj|jd�}tjj|d�}tj|�tj|�t|dd��}|jt	�Wd	QXt
jjj
d
|�}|_|j|jj�|j_|j�|jddd
tjj|d��|jddd
tjj|d��|jddd
tjj|d��|jddd
tjj|d��|jddd
tjj|d��|jddd
tjj|d��|jddd
tjj|d��|jddd
tjj|d��|jddd
|�|jddd
d�|jdd d
d!�|jdd"d
d#�|jdd$d
d%�|jdd&d
|�|jdd'd
|�|jdd(d
tjj|d)��d	S(*sE Starts a nagios server with empty config in an isolated environment s
nagios.cfgtwtsconf.dtcheckresultstlogtarchives/minimal_config.cfgNR$t	attributetlog_archive_patht	new_valueslog/archivetlog_fileslog/nagios.logtobject_cache_files
objects.cachetprecached_object_files/objects.precachet	lock_files
nagios.pidtcommand_files
nagios.cmdtstate_retention_files
retention.dattstatus_files
status.dattcfg_dirtlog_initial_statest1tenable_embedded_perlt0tevent_broker_optionss-1tillegal_macro_output_charss~$&|<>tcheck_result_patht	temp_patht	temp_files
nagios.tmp(RRRRR$topentwriteR'tmkdirtminimal_configR tParserst
config_parsertConfigRR1tparset_edit_static_file(	RttR$R'RItlog_dirtarchive_dirtfR((s4/usr/lib/python2.7/site-packages/pynag/Utils/misc.pyRis\	




cC@s/dd|jg}tjjd|dt�dS(s$ Clean up all temporary directories trms-rftcommandtshellN(RR tUtilst
runCommandR(RRZ((s4/usr/lib/python2.7/site-packages/pynag/Utils/misc.pytclean_up�scC@s.|j�|jr |j�n|j�dS(s< Stop the nagios environment and remove all temporary files N(tstopRR2R^(R((s4/usr/lib/python2.7/site-packages/pynag/Utils/misc.pyt	terminate�s
	
i
cC@s�|j�t|�}|sD|jj�}d||jjf}ntjjd|�}|\}}}tj	j
|jd�}x4tj	j|�r�|r�|d8}t
jd�q�Wd}	tj	j|�s�d}	n|ddkr�d}	n|	r�tj	jtj	j
|jd��rBttj	j
|jd��j�}
nd	}
|	}|d
7}|d7}|d7}|d
7}|d7}|jt��}t|��n|S(Ns%s -d %sRZs
nagios.pidis#Nagios pid file did not materializeis%Nagios did not start, bad return codes
nagios.logsNo log file found.sCommand: {start_command}
sExit Code: {code}
s#============
Standard out
{stdout}
s$=============
Standard Err
{stderr}
s0=============
Log File output
{log_file_output}
(tconfigure_p1_fileRRtguess_nagios_binaryR$R R\R]RRRRtexiststtimetsleepRRLtreadtformattlocalst	Exception(Rt
start_commandttimeoutt
nagios_binarytresulttcodetstdouttstderrtpid_filetstart_errortlog_file_outputtmessage((s4/usr/lib/python2.7/site-packages/pynag/Utils/misc.pytstart�s:

		$'




cC@svtjj|jd�}tjj|�s.dSt|�j�}|sSd|}ntjj	|�}t
jd�|S(Ns
nagios.pids
kill -9 %sg�?(RRRRRcRLRfR R\R]RdRe(Rtstop_commandRqtpidRm((s4/usr/lib/python2.7/site-packages/pynag/Utils/misc.pyR_�s

cC@su|js|j�|_nd|j|jf}|j�}|jddd|�tjjjd|j	�|_
dS(Ns%s %sR8t
broker_moduleR:tnagios_cfg_file(R
tguess_livestatus_pathRRRTR RPRt
LivestatusR$R(RtlineR((s4/usr/lib/python2.7/site-packages/pynag/Utils/misc.pyR�s	cC@sStjjjd|j�}|j�x'|jD]\}}|dkr/|Sq/WdS(NR$R
(R RPRQRRR	t
parse_maincfgtmaincfg_values(Rt
global_configtktv((s4/usr/lib/python2.7/site-packages/pynag/Utils/misc.pyt
guess_p1_file�s

cC@sD|js|j�|_n|j�}|jddd|j�dS(NR8R
R:(R
R�RRT(RR((s4/usr/lib/python2.7/site-packages/pynag/Utils/misc.pyRa�s	cC@sotjjjd|j�}|j�xC|jD]8\}}|dkr/d|kr/|j�d}|Sq/WdS(s� Tries to guess a path to mk-livestatus

        Returns:
            string containing full path to mk-livestatus broker_module
        R$RxRiN(R RPRQRRR	R}R~tsplit(RRR�R�tlivestatus_module((s4/usr/lib/python2.7/site-packages/pynag/Utils/misc.pyRz�s
cC@s(|j}djt��}tj|�S(s� Copies any file or directory into our environment and include it in object configuration

        Args:
            path:   full path to a nagios cfg file or a directory of cfg files

        Raises:
            Exception if path is not found
        scp -r '{path}' '{destination}/'(R'RgRhRtsystem(RRtdestinationRZ((s4/usr/lib/python2.7/site-packages/pynag/Utils/misc.pyt
import_config�s		N(RRRRRRRRR*R1R2RR^R`RuR_RR�RaRzR�(((s4/usr/lib/python2.7/site-packages/pynag/Utils/misc.pyRs"			
			6		#	
			s�1
    define timeperiod {
      alias                          24 Hours A Day, 7 Days A Week
      friday          00:00-24:00
      monday          00:00-24:00
      saturday        00:00-24:00
      sunday          00:00-24:00
      thursday        00:00-24:00
      timeperiod_name                24x7
      tuesday         00:00-24:00
      wednesday       00:00-24:00
    }

    define timeperiod {
      alias                          24x7 Sans Holidays
      friday          00:00-24:00
      monday          00:00-24:00
      saturday        00:00-24:00
      sunday          00:00-24:00
      thursday        00:00-24:00
      timeperiod_name                24x7_sans_holidays
      tuesday         00:00-24:00
      use		us-holidays		; Get holiday exceptions from other timeperiod
      wednesday       00:00-24:00
    }

    define contactgroup {
      alias                          Nagios Administrators
      contactgroup_name              admins
      members                        nagiosadmin
    }

    define command {
      command_line                   $USER1$/check_ping -H $HOSTADDRESS$ -w 3000.0,80% -c 5000.0,100% -p 5
      command_name                   check-host-alive
    }

    define command {
      command_line                   $USER1$/check_dhcp $ARG1$
      command_name                   check_dhcp
    }

    define command {
      command_line                   $USER1$/check_ftp -H $HOSTADDRESS$ $ARG1$
      command_name                   check_ftp
    }

    define command {
      command_line                   $USER1$/check_hpjd -H $HOSTADDRESS$ $ARG1$
      command_name                   check_hpjd
    }

    define command {
      command_line                   $USER1$/check_http -I $HOSTADDRESS$ $ARG1$
      command_name                   check_http
    }

    define command {
      command_line                   $USER1$/check_imap -H $HOSTADDRESS$ $ARG1$
      command_name                   check_imap
    }

    define command {
      command_line                   $USER1$/check_disk -w $ARG1$ -c $ARG2$ -p $ARG3$
      command_name                   check_local_disk
    }

    define command {
      command_line                   $USER1$/check_load -w $ARG1$ -c $ARG2$
      command_name                   check_local_load
    }

    define command {
      command_line                   $USER1$/check_mrtgtraf -F $ARG1$ -a $ARG2$ -w $ARG3$ -c $ARG4$ -e $ARG5$
      command_name                   check_local_mrtgtraf
    }

    define command {
      command_line                   $USER1$/check_procs -w $ARG1$ -c $ARG2$ -s $ARG3$
      command_name                   check_local_procs
    }

    define command {
      command_line                   $USER1$/check_swap -w $ARG1$ -c $ARG2$
      command_name                   check_local_swap
    }

    define command {
      command_line                   $USER1$/check_users -w $ARG1$ -c $ARG2$
      command_name                   check_local_users
    }

    define command {
      command_line                   $USER1$/check_nt -H $HOSTADDRESS$ -p 12489 -v $ARG1$ $ARG2$
      command_name                   check_nt
    }

    define command {
      command_line                   $USER1$/check_ping -H $HOSTADDRESS$ -w $ARG1$ -c $ARG2$ -p 5
      command_name                   check_ping
    }

    define command {
      command_line                   $USER1$/check_pop -H $HOSTADDRESS$ $ARG1$
      command_name                   check_pop
    }

    define command {
      command_line                   $USER1$/check_smtp -H $HOSTADDRESS$ $ARG1$
      command_name                   check_smtp
    }

    define command {
      command_line                   $USER1$/check_snmp -H $HOSTADDRESS$ $ARG1$
      command_name                   check_snmp
    }

    define command {
      command_line                   $USER1$/check_ssh $ARG1$ $HOSTADDRESS$
      command_name                   check_ssh
    }

    define command {
      command_line                   $USER1$/check_tcp -H $HOSTADDRESS$ -p $ARG1$ $ARG2$
      command_name                   check_tcp
    }

    define command {
      command_line                   $USER1$/check_udp -H $HOSTADDRESS$ -p $ARG1$ $ARG2$
      command_name                   check_udp
    }

    define contact {
      name                           generic-contact
      host_notification_commands     notify-host-by-email
      host_notification_options      d,u,r,f,s
      host_notification_period       24x7
      register                       0
      service_notification_commands  notify-service-by-email
      service_notification_options   w,u,c,r,f,s
      service_notification_period    24x7
    }

    define host {
      name                           generic-host
      event_handler_enabled          1
      failure_prediction_enabled     1
      flap_detection_enabled         1
      notification_period            24x7
      notifications_enabled          1
      process_perf_data              1
      register                       0
      retain_nonstatus_information   1
      retain_status_information      1
      max_check_attempts             3
    }

    define host {
      name                           generic-printer
      use                            generic-host
      check_command                  check-host-alive
      check_interval                 5
      check_period                   24x7
      contact_groups                 admins
      max_check_attempts             10
      notification_interval          30
      notification_options           d,r
      notification_period            workhours
      register                       0
      retry_interval                 1
      statusmap_image                printer.png
    }

    define host {
      name                           generic-router
      use                            generic-switch
      register                       0
      statusmap_image                router.png
    }

    define service {
      name                           generic-service
      action_url                     /pnp4nagios/graph?host=$HOSTNAME$&srv=$SERVICEDESC$
      active_checks_enabled          1
      check_freshness                0
      check_period                   24x7
      event_handler_enabled          1
      failure_prediction_enabled     1
      flap_detection_enabled         1
      icon_image                     unknown.gif
      is_volatile                    0
      max_check_attempts             3
      normal_check_interval          10
      notes_url                      /adagios/objectbrowser/edit_object/object_type=service/shortname=$HOSTNAME$/$SERVICEDESC$
      notification_interval          60
      notification_options           w,u,c,r
      notification_period            24x7
      notifications_enabled          1
      obsess_over_service            1
      parallelize_check              1
      passive_checks_enabled         1
      process_perf_data              1
      register                       0
      retain_nonstatus_information   1
      retain_status_information      1
      retry_check_interval           2
    }

    define host {
      name                           generic-switch
      use                            generic-host
      check_command                  check-host-alive
      check_interval                 5
      check_period                   24x7
      contact_groups                 admins
      max_check_attempts             10
      notification_interval          30
      notification_options           d,r
      notification_period            24x7
      register                       0
      retry_interval                 1
      statusmap_image                switch.png
    }

    define host {
      name                           linux-server
      use                            generic-host
      check_command                  check-host-alive
      check_interval                 5
      check_period                   24x7
      contact_groups                 admins
      max_check_attempts             10
      notification_interval          120
      notification_options           d,u,r
      notification_period            workhours
      register                       0
      retry_interval                 1
    }

    define service {
      name                           local-service
      use                            generic-service
      max_check_attempts             4
      normal_check_interval          5
      register                       0
      retry_check_interval           1
    }

    define contact {
      use                            generic-contact
      alias                          Nagios Admin
      contact_name                   nagiosadmin
      email                          nagios@localhost
    }

    define timeperiod {
      alias                          No Time Is A Good Time
      timeperiod_name                none
    }

    define command {
      command_line                   /usr/bin/printf "%b" "***** Nagios *****\n\nNotification Type: $NOTIFICATIONTYPE$\nHost: $HOSTNAME$\nState: $HOSTSTATE$\nAddress: $HOSTADDRESS$\nInfo: $HOSTOUTPUT$\n\nDate/Time: $LONGDATETIME$\n" | /bin/mail -s "** $NOTIFICATIONTYPE$ Host Alert: $HOSTNAME$ is $HOSTSTATE$ **" $CONTACTEMAIL$
      command_name                   notify-host-by-email
    }

    define command {
      command_line                   /usr/bin/printf "%b" "***** Nagios *****\n\nNotification Type: $NOTIFICATIONTYPE$\n\nService: $SERVICEDESC$\nHost: $HOSTALIAS$\nAddress: $HOSTADDRESS$\nState: $SERVICESTATE$\n\nDate/Time: $LONGDATETIME$\n\nAdditional Info:\n\n$SERVICEOUTPUT$\n" | /bin/mail -s "** $NOTIFICATIONTYPE$ Service Alert: $HOSTALIAS$/$SERVICEDESC$ is $SERVICESTATE$ **" $CONTACTEMAIL$
      command_name                   notify-service-by-email
    }

    define command {
      command_line                   /usr/bin/printf "%b" "$LASTHOSTCHECK$\t$HOSTNAME$\t$HOSTSTATE$\t$HOSTATTEMPT$\t$HOSTSTATETYPE$\t$HOSTEXECUTIONTIME$\t$HOSTOUTPUT$\t$HOSTPERFDATA$\n" >> /var/log/nagios/host-perfdata.out
      command_name                   process-host-perfdata
    }

    define command {
      command_line                   /usr/bin/printf "%b" "$LASTSERVICECHECK$\t$HOSTNAME$\t$SERVICEDESC$\t$SERVICESTATE$\t$SERVICEATTEMPT$\t$SERVICESTATETYPE$\t$SERVICEEXECUTIONTIME$\t$SERVICELATENCY$\t$SERVICEOUTPUT$\t$SERVICEPERFDATA$\n" >> /var/log/nagios/service-perfdata.out
      command_name                   process-service-perfdata
    }

    define timeperiod {
      alias                          U.S. Holidays
      december 25             00:00-00:00     ; Christmas
      january 1               00:00-00:00     ; New Years
      july 4                  00:00-00:00     ; Independence Day
      monday -1 may           00:00-00:00     ; Memorial Day (last Monday in May)
      monday 1 september      00:00-00:00     ; Labor Day (first Monday in September)
      name			us-holidays
      thursday 4 november     00:00-00:00     ; Thanksgiving (4th Thursday in November)
      timeperiod_name                us-holidays
    }

    define host {
      name                           windows-server
      use                            generic-host
      check_command                  check-host-alive
      check_interval                 5
      check_period                   24x7
      contact_groups                 admins
      hostgroups
      max_check_attempts             10
      notification_interval          30
      notification_options           d,r
      notification_period            24x7
      register                       0
      retry_interval                 1
    }

    define hostgroup {
      alias                          Windows Servers
      hostgroup_name                 windows-servers
    }

    define timeperiod {
      alias                 Normal Work Hours
      friday                09:00-17:00
      monday                09:00-17:00
      thursday              09:00-17:00
      timeperiod_name       workhours
      tuesday               09:00-17:00
      wednesday             09:00-17:00
    }

    define command {
        command_name    check_dummy
        command_line    $USER1$/check_dummy!$ARG1$!$ARG2$
    }


    define host {
        host_name           ok_host
        use                 generic-host
        address	            ok_host
        max_check_attempts	1
        check_command       check_dummy!0!Everything seems to be okay
    }


    define service {
        host_name           ok_host
        use                 generic-service
        service_description ok service 1
        check_command       check_dummy!0!Everything seems to be okay
    }

    (Rt
__future__RRRRdtpynag.Parsers.config_parserR tpynag.Parsers.livestatustpynag.Modeltsixtpynag.errorsRtpynag.UtilsRRRtobjectRRO(((s4/usr/lib/python2.7/site-packages/pynag/Utils/misc.pyt<module>s ��I