Get the book Learning Ruby. 

Worth it. 

> On Nov 27, 2013, at 7:44 AM, Dan White <[email protected]> wrote:
> 
> Very nice.
> I am still learning Ruby and this will help
> 
> Thanks.
> 
> “Sometimes I think the surest sign that intelligent life exists elsewhere in 
> the universe is that none of it has tried to contact us.”
> Bill Waterson (Calvin & Hobbes)
> 
> From: "David Portabella" <[email protected]>
> To: [email protected]
> Sent: Wednesday, November 27, 2013 10:12:48 AM
> Subject: Re: [Puppet Users] get a *structured* version of the puppet agent 
> output
> 
> Thanks again! It is great to use the puppet report yaml files!
> here there is an example script that prints all resources statuses, 
> then it filters them by taking only the services,
> then it filters them by taking only the services changed to running.
> 
> test.ruby
> #!/usr/bin/ruby 
> 
> require 'puppet' 
> filename = ARGV.first 
> report = YAML.load_file(filename) 
> rs = report.resource_statuses.values.sort_by{|r| r.resource}
> 
> puts "PRINT ALL RESOURCES STATUSES."
> rs.each do |r| 
>   puts "#{r.change_count} #{r.events.map {|e| e.previous_value}} 
> #{r.events.map {|e| e.desired_value}} #{r.resource}"
> end 
> 
> puts "PRINT ALL SERVICES."
> services = rs.select{|r| r.resource_type == 'Service'}
> services.each do |r| 
>   puts "#{r.change_count} #{r.events.map {|e| e.previous_value}} 
> #{r.events.map {|e| e.desired_value}} #{r.resource}"
> end 
> 
> puts "PRINT ALL SERVICES CHANGED TO RUNNING."
> services_changed_to_running = rs.select{|r| r.resource_type == 'Service' && 
> r.change_count > 0 && r.events.index { |e| e.desired_value == :running } != 
> nil}
> services_changed_to_running.each do |r| 
>   puts "#{r.change_count} #{r.events.map {|e| e.previous_value}} 
> #{r.events.map {|e| e.desired_value}} #{r.resource}"
> end 
>  
> example output:
> $ test.ruby /var/opt/lib/pe-puppet/reports/test/201311261645.yaml 
> PRINT ALL RESOURCES STATUSES.
> 1 [:absent] [:directory] File[/var/app]
> 1 [:absent] [:file] File[/var/app/app.conf]
> 2 [0, "755"] [91, "775"] File[/var/log/tomcat6]
> 0 [] [] Filebucket[puppet]
> 1 [:absent] [:present] Group[release]
> 1 [:absent] [:present] Package[varnish]
> 0 [] [] Schedule[weekly]
> 1 [:stopped] [:running] Service[varnish]
> 0 [] [] Tidy[/etc/collectd.d/]
> 1 ["/sbin/nologin"] ["/bin/bash"] User[tomcat]
> ...
> 
> PRINT ALL SERVICES.
> 1 [:stopped] [:running] Service[collectd]
> 1 [:stopped] [:running] Service[logstash-agent]
> 1 [:true] [:false] Service[logstash]
> 1 [:stopped] [:running] Service[nginx]
> 0 [] [] Service[rsyslog]
> 1 [:stopped] [:running] Service[statsd]
> 1 [:false] [:true] Service[supervisord]
> 1 [:stopped] [:running] Service[varnish]
> 
> PRINT ALL SERVICES CHANGED TO RUNNING
> 1 [:stopped] [:running] Service[collectd]
> 1 [:stopped] [:running] Service[logstash-agent]
> 1 [:stopped] [:running] Service[nginx]
> 1 [:stopped] [:running] Service[statsd]
> 1 [:stopped] [:running] Service[varnish]
> 
> -- 
> You received this message because you are subscribed to the Google Groups 
> "Puppet Users" group.
> To unsubscribe from this group and stop receiving emails from it, send an 
> email to [email protected].
> To view this discussion on the web visit 
> https://groups.google.com/d/msgid/puppet-users/c70db1f6-b133-4290-a8e1-827ea239028b%40googlegroups.com.
> For more options, visit https://groups.google.com/groups/opt_out.
> -- 
> You received this message because you are subscribed to a topic in the Google 
> Groups "Puppet Users" group.
> To unsubscribe from this topic, visit 
> https://groups.google.com/d/topic/puppet-users/cHpZlKkPmr4/unsubscribe.
> To unsubscribe from this group and all its topics, send an email to 
> [email protected].
> To view this discussion on the web visit 
> https://groups.google.com/d/msgid/puppet-users/1253465309.4764508.1385567092577.JavaMail.root%40sz0126a.westchester.pa.mail.comcast.net.
> For more options, visit https://groups.google.com/groups/opt_out.

-- 
You received this message because you are subscribed to the Google Groups 
"Puppet Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/puppet-users/36085646-13B6-4457-A36B-B2C8F97A603E%40me.com.
For more options, visit https://groups.google.com/groups/opt_out.

Reply via email to