403Webshell
Server IP : 77.68.64.20  /  Your IP : 216.73.217.31
Web Server : Apache
System : Linux hp3-wp-1011317.hostingp3.local 3.10.0-1160.144.1.el7.tuxcare.els8.x86_64 #1 SMP Sun Jul 5 17:25:39 UTC 2026 x86_64
User : csh2392878 ( 2033753)
PHP Version : 8.3.30
Disable Function : shell_exec,exec,system,popen,set_time_limit
MySQL : OFF  |  cURL : ON  |  WGET : ON  |  Perl : ON  |  Python : ON  |  Sudo : ON  |  Pkexec : ON
Directory :  /usr/share/puppet/ext/

Upload File :
current_dir [ Writeable ] document_root [ Writeable ]

 

Command :


[ Back ]     

Current File : /usr/share/puppet/ext/upload_facts.rb
#!/usr/bin/env ruby

require 'net/https'
require 'openssl'
require 'openssl/x509'
require 'optparse'
require 'pathname'
require 'yaml'

require 'puppet'
require 'puppet/network/http_pool'

class Puppet::Application::UploadFacts < Puppet::Application
  run_mode :master

  option('--debug', '-d')
  option('--verbose', '-v')

  option('--logdest DEST', '-l DEST') do |arg|
    Puppet::Util::Log.newdestination(arg)
    options[:setdest] = true
  end

  option('--minutes MINUTES', '-m MINUTES') do |minutes|
    options[:time_limit] = 60 * minutes.to_i
  end

  def help
    print <<HELP
== Synopsis

Upload cached facts to the inventory service.

= Usage

  upload_facts [-d|--debug] [-v|--verbose] [-m|--minutes <minutes>]
               [-l|--logdest syslog|<file>|console]

= Description

This command will read YAML facts from the puppet master's YAML directory, and
save them to the configured facts_terminus. It is intended to be used with the
facts_terminus set to inventory_service, in order to ensure facts which have
been cached locally due to a temporary failure are still uploaded to the
inventory service.

= Usage Notes

upload_facts is intended to be run from cron, with the facts_terminus set to
inventory_service. The +--minutes+ argument should be set to the length of time
between upload_facts runs. This will ensure that only new YAML files are
uploaded.

= Options

Note that any setting that's valid in the configuration file
is also a valid long argument.  For example, 'server' is a valid configuration
parameter, so you can specify '--server <servername>' as an argument.

See the configuration file documentation at
http://docs.puppetlabs.com/references/stable/configuration.html for
the full list of acceptable parameters. A commented list of all
configuration options can also be generated by running puppet agent with
'--genconfig'.

minutes::
  Limit the upload only to YAML files which have been added within the last n
  minutes.
HELP

    exit
  end

  def setup
    # Handle the logging settings.
    if options[:debug] or options[:verbose]
      if options[:debug]
        Puppet::Util::Log.level = :debug
      else
        Puppet::Util::Log.level = :info
      end

      Puppet::Util::Log.newdestination(:console) unless options[:setdest]
    end

    exit(Puppet.settings.print_configs ? 0 : 1) if Puppet.settings.print_configs?
  end

  def main
    dir = Pathname.new(Puppet[:yamldir]) + 'facts'

    cutoff = options[:time_limit] ? Time.now - options[:time_limit] : Time.at(0)

    files = dir.children.select do |file|
      file.extname == '.yaml' && file.mtime > cutoff
    end

    failed = false

    terminus = Puppet::Node::Facts.indirection.terminus

    files.each do |file|
      facts = YAML.load_file(file)

      request = Puppet::Indirector::Request.new(:facts, :save, facts)

      # The terminus warns for us if we fail.
      if terminus.save(request)
        Puppet.info "Uploaded facts for #{facts.name} to inventory service"
      else
        failed = true
      end
    end

    exit !failed
  end
end

Puppet::Application::UploadFacts.new.run

Youez - 2016 - github.com/yon3zu
LinuXploit