I tried as you said and below the registrationmonitor.rb content.

================================
# discovers against directory of yaml files instead of the traditional 
network discovery
# the input must be a directory of files as written out by the 
registration-monitor plugin
require 'mcollective/rpc/helpers'
require 'yaml'

module MCollective
  class Discovery
    class Registrationmonitor
      def self.parse_hosts(dir, hosts)
        data = {}
        hosts.each do |host|
          data[host] = YAML.load(File.read("#{dir}/#{host}"))
        end
        data
      end

      def self.discover(filter, timeout, limit=0, client=nil)
        newerthan = Time.now.to_i - 
Integer(Config.instance.pluginconf["registration.criticalage"] || 86400)

        unless client.options[:discovery_options].empty?
          directory = client.options[:discovery_options].last
        else
          raise("Need --discovery_options to a directory")
        end

        discovered = []
        Dir.new(directory).each do |file|
          next if file =~ /^\.\.?$/
          if File.mtime("#{directory}/#{file}").to_i >= newerthan
            discovered.push file
          end
        end

        discovered.map do |host|
          raise "Identities can only match /\w\.\-/, host #{host} does not 
match" unless host.match(/^[\w\.\-]+$/)
          host
        end

        filter['identity'].each do |identity|
          discovered = discovered.grep regexy_string(identity)
        end

        parsed_hostdata = parse_hosts(directory, discovered)

        discovered = discovered.select { |identity| 
parsed_hostdata[identity]["collectives"].include?(client.options[:collective]) 
}

        filter.keys.each do |key|
          case key
            when "fact"
              discovered = fact_search(filter["fact"], discovered, 
parsed_hostdata)

            when "cf_class"
              discovered = class_search(filter["cf_class"], discovered, 
parsed_hostdata)

            when "agent"
              discovered = agent_search(filter["agent"], discovered, 
parsed_hostdata)

            when "identity"
          end
        end
        discovered
      end

      def self.fact_search(filter, collection, parsed_hostdata)
        filter.each do |f|
          fact = f[:fact]
          value = f[:value]
          re = regexy_string(value)

          case f[:operator]
            when "==", "=~"
              collection = collection.select { |identity| 
re.match(parsed_hostdata[identity]["facts"][fact]) }
            when "<="
              collection = collection.select { |identity| value <= 
parsed_hostdata[identity]["facts"][fact] }
            when ">="
              collection = collection.select { |identity| value >= 
parsed_hostdata[identity]["facts"][fact] }
            when "<"
              collection = collection.select { |identity| value < 
parsed_hostdata[identity]["facts"][fact] }
            when ">"
              collection = collection.select { |identity| value > 
parsed_hostdata[identity]["facts"][fact] }
            when "!="
              collection = collection.select { |identity| 
!re.match(parsed_hostdata[identity]["facts"][fact]) }
            else
              raise "Cannot perform %s matches for facts using the 
registrationmonitor discovery method" % f[:operator]
          end
        end
        collection
      end

      def self.class_search(filter, collection, parsed_hostdata)
        filter.each do |f|
          re = regexy_string(f)
          collection = collection.select { |identity| 
parsed_hostdata[identity]["classes"].find { |klass| re.match(klass) } }
        end
        collection
      end

      def self.agent_search(filter, collection, parsed_hostdata)
        filter.each do |f|
          re = regexy_string(f)
          collection = collection.select { |identity| 
parsed_hostdata[identity]["agentlist"].find { |klass| re.match(klass) } }
        end
        collection
      end

      def self.regexy_string(string)
        if string.match("^/")
          Regexp.new(string.gsub("\/", ""))
        else
          Regexp.new("^#{string}$")
        end
      end
    end
  end
end
=======================

But when run mco command getting "No request sent, we did not discover any 
nodes."

# mco shell "uname -a" --do /data/mcollective_inventory/ --dm 
registrationmonitor -v -I testserver123 
Discovering hosts using the registrationmonitor method .... 0


No request sent, we did not discover any nodes.
#

Also I tried to parse that yaml file in the same way mentioned on 
registrationmonitor.rb and it working.

irb(main):004:0> require 'rubygems'
=> true
irb(main):005:0> require 'yaml'
=> true
irb(main):006:0> data[host] = 
YAML.load(File.read("/data/mcollective_inventory/testserver123 "))
=> {"collectives"=>["mcollective"], "facts"=>{"hardwareisa"=>"x86_64",
.
.
.
irb(main):007:0> 
irb(main):016:0> parsed_hostdata = data
irb(main):022:0> parsed_hostdata["testserver123 "]["facts"]["hostname"]
=> "testserver123 "
irb(main):023:0>



Thanks
Ravi

On Saturday, March 11, 2017 at 12:12:35 PM UTC+5:30, R.I.Pienaar wrote:
>
> change :collectives to "collectives": 
>
>
> https://github.com/puppetlabs/mcollective-plugins/blob/master/agent/registration-monitor/discovery/registrationmonitor.rb#L45
>  
>
> will probably have to similarly change :facts here 
>
> https://github.com/puppetlabs/mcollective-plugins/blob/master/agent/registration-monitor/discovery/registrationmonitor.rb#L72-L82
>  
>
> and :classes 
>
> https://github.com/puppetlabs/mcollective-plugins/blob/master/agent/registration-monitor/discovery/registrationmonitor.rb#L93
>  
>
> and :agentlist 
>
> https://github.com/puppetlabs/mcollective-plugins/blob/master/agent/registration-monitor/discovery/registrationmonitor.rb#L101
>  
>
> On Sat, Mar 11, 2017, at 07:06, [email protected] <javascript:> wrote: 
> > Here is that server inventory data file, 
> > 
> > ========================================================= 
> > --- 
> > identity: testserver123 
> > facts: 
> >   uptime: 383 days 
> >   memoryfree: 5.68 GB 
> >   title: main 
> >   ps: ps -ef 
> >   memoryfree_mb: "5816.89" 
> >   lsbrelease: 
> > 
> ":base-4.0-amd64:base-4.0-noarch:core-4.0-amd64:core-4.0-noarch:graphics-4.0-amd64:graphics-4.0-noarch:printing-4.0-amd64:printing-4.0-noarch"
>  
>
> >   memorysize_mb: "8015.77" 
> >   servername: testserver123.server.com 
> >   path: /sbin:/usr/sbin:/bin:/usr/bin 
> >   root_home: /root 
> >   sshfp_dsa: |- 
> >     SSHFP 2 1 37250f7d9eac0e059b6556ddcf6a885750859b4a 
> >     SSHFP 2 2 
> > ae228dc1547003913e9b545ad7b04a994266ed66a73d4412cbca9f24437886f6 
> >   id: root 
> >   swapfree: 7.98 GB 
> >   memorysize: 7.83 GB 
> >   rubysitedir: /usr/lib/ruby/site_ruby/1.8 
> >   domain: server.com 
> >   uptime_days: "383" 
> >   network_eth1: xx.xx.xx.xx 
> >   uptime_seconds: "35787609" 
> >   kernel: Linux 
> >   concat_basedir: /var/lib/puppet/concat 
> >   macaddress_eth0: 00:23:C6:DD:00:01 
> >   clientnoop: "false" 
> >   serverip: xx.xx.xx.xx 
> >   netmask_eth0: xx.xx.xx.xx 
> >   facterversion: 2.1.0 
> >   augeasversion: 1.0.0 
> >   ipaddress_eth0: xx.xx.xx.xx 
> >   selinux: "false" 
> >   is_virtual: "true" 
> >   processor3: Intel(R) Xeon(R) CPU E5-2660 0 @ 2.20GHz 
> >   blockdevice_sdb_size: "2097152" 
> >   kernelversion: 3.8.13 
> >   processor0: Intel(R) Xeon(R) CPU E5-2660 0 @ 2.20GHz 
> >   interfaces: eth0,eth1,lo 
> >   rubyversion: 1.8.7 
> >   sshdsakey: 
> > 
> AAAAB3NzaC1kc3MAAACBAM8zDRlclm28o9xRTMmSYtP8D8V2HgZsKH2m5LY3UqUeOa5L4NamZHEECC18Gd1ZnmAVEFplfQGzaOsOVe3ldx3OVY7/VHGkfAwHRiWNsf8ni87CUzx7Ayt+d0j5dlCbeZXtlpXO0dqFA7NGVn7UGTX+oE2wUFGOe8zaT6FZZf19AAAAFQCyCeA3YrZCT3TJ9ysC2aHI4KqdrwAAAIEAlznBnQRMPrfwp5wtqK/gXWnsTgf8rkHvnXeNoRc+HzJ6tmJvYJebNHk6JBQu4cjfZSFD23DRec45S4/d9DGEodsh80m1IH7dnqi57V2B4OjwjlBjB9jqOBcxMUUBcJhDF498uA3Al31wEaFLoAAACBALkLN0KW4kK2G+5kxVMOQglhaxouu5n+r7QbGiuB5n/anzMgKHA0XOiGYn6yXW9hN2BSudq3QGyW2Bze73qadjLwd7RozhTyYD1B/AX1QkLgiFIV825vrAVD/iQT56mc7QIgySXibMaptNgufd+5F/iXQnyQRTt1bjI3zR6fR4hZ
>  
>
> >   uptime_hours: "9196" 
> >   puppet_vardir: /var/lib/puppet 
> >   ip6tables_version: 1.4.7 
> >   lsbdistcodename: n/a 
> >   blockdevices: sda,sdb,sdc 
> >   virtual: xen 
> >   netmask: xx.xxx.xx.xx 
> >   operatingsystem: Linux 
> >   puppetversion: 3.6.2 
> >   ipaddress_lo: 127.0.0.1 
> >   hostname: testserver123 
> >   macaddress_eth1: 00:21:F6:FF:0E:01 
> >   partitions: sdb1size4095filesystemmsdos" UUID="S2DC-F4ED" 
> > 
> TYPE="vfatsda1size4192964filesystemext4mount/uuid927645ac-5cba-460e-a035-29e093d5998dsda2size10474380filesystemext4mount/usruuida1422e95-3b47-4e7b-b021-3a8dba7a001bsda3size6281415filesystemext4mount/varuuid6e2a7fcc-7a79-4a12-86f8-bec1ab40a5b0sda4size2sda5size8385929filesystemext4mount/oemuuid3c96ed2e-5a93-4ca2-b2ef-4617c8f81c98sda6size8385929filesystemext4uuid0c0ba91b-f6e8-478c-a23e-5d889cfbe940sda7size2120579filesystemext4mount/homeuuid29fc3979-70e6-4638-ac42-867306d2bca4
>  
>
> >   swapsize_mb: "8192.00" 
> >   netmask_eth1: xx.xx.xx.xx 
> >   netmask_lo: 255.0.0.0 
> >   ipaddress_eth1: xx.xx.xx.xx 
> >   architecture: x86_64 
> >   physicalprocessorcount: "1" 
> >   macaddress: 33:DD:43:GD:23 
> >   processor1: Intel(R) Xeon(R) CPU E5-2660 0 @ 2.20GHz 
> >   osfamily: RedHat 
> >   lsbdistrelease: "6.7" 
> >   mtu_eth0: "1500" 
> >   blockdevice_sdc_size: "8589934592" 
> >   network_lo: 127.0.0.0 
> >   kernelrelease: 3.8.13-98.4.el6.x86_64 
> >   ipaddress: xx.xx.xx.xx 
> >   lsbdistdescription: Linux Server release 6.7 
> >   swapfree_mb: "8172.21" 
> >   processorcount: "4" 
> >   fqdn: testserver123.server.com 
> >   mtu_lo: "65536" 
> >   sshrsakey: 
> > 
> AAAAB3NzaC1yc2EAAAABIwAAAQEApQc3boaYakhnFwersascMZs9emkYynhugKOY4l7duN4zkxflYysVDKfjvo9+bDDmXaZL9IVZfeFriGrqtw05IDumDGLZqEoOGYkoE/c4cyzRGLh/ROJqkLgM8fhlvi0DlnTuSMAjQagT6RwK+nGj6+mrPVg/Jjh3M57ecorgZAPm37mw3xS2Ks9MzcZ7hiHujxbNEogamFrRkOb9ZK9jzj0DXRDmlS01U0hFWv0P9YKTRI6iBIG1r+G+uZo84Z56qEvYWA+74PZD0DgtJIVUB65CBMXnX/k/WwRqXxGVKxTG72zOe6V2+QCErO7toasdweASFfwe==
>  
>
> >   sshfp_rsa: |- 
> >     SSHFP 1 1 931fd4af50028d8234asdewr232a76443200af86fd 
> >     SSHFP 1 2 2cbc81201f0c9ca831734sc234f2135f23fd130c323653db0b2c0 
> >   blockdevice_sda_size: "20402143232" 
> >   network_eth0: xx.xx.xx.xx 
> >   is_pe: "false" 
> >   lsbmajdistrelease: "6" 
> >   iptables_version: 1.4.7 
> >   filesystems: ext4,iso9660,vfat 
> >   hardwareisa: x86_64 
> >   gemhome: /usr/lib/ruby/gems/1.8 
> >   operatingsystemrelease: "6.7" 
> >   swapsize: 8.00 GB 
> >   allow_virtual_packages: "false" 
> >   uniqueid: sdf32345f 
> >   processor2: Intel(R) Xeon(R) CPU E5-2660 0 @ 2.20GHz 
> >   serverversion: 3.6.2 
> >   operatingsystemmajrelease: "6" 
> >   clientversion: 3.6.2 
> >   mtu_eth1: "1500" 
> >   hardwaremodel: x86_64 
> >   clientcert: testserver123 
> >   timezone: CST 
> >   kernelmajversion: "3.8" 
> >   lsbdistid: LinuxServer 
> > agentlist: 
> > - nrpe 
> > - puppet 
> > - package 
> > - discovery 
> > - rpcutil 
> > - shell 
> > - service 
> > classes: [] 
> > 
> > collectives: 
> > - mcollective 
> > ========================================= 
> > 
> > On Saturday, March 11, 2017 at 11:22:21 AM UTC+5:30, R.I.Pienaar wrote: 
> > > 
> > > 
> > > 
> > > On Sat, Mar 11, 2017, at 06:46, [email protected] <javascript:> 
> wrote: 
> > > > Hey, 
> > > > 
> > > > No I did not make any change on that file. I just simply downloaded 
> .rb 
> > > > and 
> > > > .ddl files 
> > > > from 
> > > > 
> > > 
> https://raw.githubusercontent.com/puppetlabs/mcollective-plugins/master/agent/registration-monitor/discovery/
>  
> > > > and tried. 
> > > 
> > > error suggest the data file is not in the correct format, so show a 
> data 
> > > file. 
> > > 
> > > Still, a different line in that file would make the error than what 
> your 
> > > error shows. 
> > > 
> > 
> > -- 
> > 
> > --- 
> > You received this message because you are subscribed to the Google 
> Groups 
> > "mcollective-users" group. 
> > To unsubscribe from this group and stop receiving emails from it, send 
> an 
> > email to [email protected] <javascript:>. 
> > For more options, visit https://groups.google.com/d/optout. 
>
>
> -- 
> R.I.Pienaar / www.devco.net / @ripienaar 
>

-- 

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

Reply via email to