Upgrade to Pro — share decks privately, control downloads, hide ads and more …

MCollective as an Integration Layer

MCollective as an Integration Layer

At PuppetCamp in April 2014, @jtopper spoke about using MCollective as an integration layer, covering our two projects ZCollective (http://www.scalefactory.com/resources/github/zcollective) and sf-deploy (https://github.com/scalefactory/sf-deploy).

The talk was recorded, and this recording can be seen at https://www.youtube.com/watch?v=usemi8WdGHo

Avatar for The Scale Factory

The Scale Factory

April 04, 2014
Tweet

More Decks by The Scale Factory

Other Decks in Technology

Transcript

  1. Zabbix • Distributed monitoring system • Fetches time series data

    - can alert on anomaly • Uses MySQL • Multiple data sources: • Zabbix agent / sender • SNMP poll / traps • JMX
  2. ZCollective include MCollective::RPC! ! mc = rpcclient("rpcutil", :debug => true)!

    ! mc.discover.sort.each do |host|! ! inventory = mc.custom_request( ! "inventory", {}, host,! { "identity" => host }! ).first! ! do_some_zabbix_magic(inventory)! ! end
  3. ZCollective def do_some_zabbix_magic(inventory)! ! # If the host isn’t added

    to Zabbix! # Add the host using the API! # For each Puppet class on this host! # If there’s a Zabbix template by this name! # Assign that template to the host.! # end! # end! # end! ! # If the host is already in Zabbix! # Make sure all templates correctly assigned! # end ! ! end
  4. Code class MCollective::Application::Sfdeploy < MCollective::Application! ! def main! ! action

    = configuration[:action]! ! mc = rpcclient("sfdeploy")! ! printrpc mc.send(! action,! :application => configuration[:application],! :branch => configuration[:branch],! :tag => configuration[:tag],! :groups => configuration[:groups],! :options => options! )! ! printrpcstats! end
  5. Code module MCollective! module Agent! class Sfdeploy < RPC::Agent! !

    all_actions.each do |act|! action act do! ! sf_deploy = config.pluginconf["sfdeploy.binary"] || "sf-deploy"! deploy_user = config.pluginconf["sfdeploy.user"]|| nil! ! command = "#{sf_deploy} -a #{request[:application]} -v "! command << "-b #{request[:branch]} " if request[:branch]! command << "-t #{request[:tag]} " if request[:tag]! command << "-g #{request[:groups]} " if request[:groups]! command << act! ! if deploy_user! to_run = "su #{deploy_user} -c \"#{command}\""! else! to_run = command! end