using nagios with chef

55
Configuring Nagios with Chef Bryan McLellan Technical Program Manager, Open Source [email protected] / @btmspox

Upload: bryan-mclellan

Post on 29-Jan-2018

6.287 views

Category:

Technology


0 download

TRANSCRIPT

Page 1: Using Nagios with Chef

Configuring Nagios with ChefBryan McLellanTechnical Program Manager, Open [email protected] / @btmspox

Page 2: Using Nagios with Chef

Overview

•Who am I?

•Why automation

• Introduction to Chef

•Nagios Demo

•Questions

Page 3: Using Nagios with Chef

Who am I?

• ChefEarly developer, user, pundit

• 10+ years in Systems AdministrationComputer repair, ISPs, Corporate IT,Web operations

• Event Logistics VolunteerTraffic Control, Parking, Communications, Networking, Emergency Management

• Hacker-Operator

Page 4: Using Nagios with Chef

How did we get here?

Bare Metal Deployment

Page 5: Using Nagios with Chef

How did we get here?

Bare Metal Deployment

• Purchasing

Page 6: Using Nagios with Chef

How did we get here?

Bare Metal Deployment

• Purchasing

• Vendor build

Page 7: Using Nagios with Chef

How did we get here?

Bare Metal Deployment

• Purchasing

• Vendor build

• Delivery

Page 8: Using Nagios with Chef

How did we get here?

Bare Metal Deployment

• Purchasing

• Vendor build

• Delivery

• Installation

Page 9: Using Nagios with Chef

How did we get here?

Bare Metal Deployment

• Purchasing

• Vendor build

• Delivery

• Installation

• OS deployment

Page 10: Using Nagios with Chef

How did we get here?

Bare Metal Deployment

• Purchasing

• Vendor build

• Delivery

• Installation

• OS deployment

• Application deployment

Page 11: Using Nagios with Chef

How did we get here?

Bare Metal Deployment

• Purchasing

• Vendor build

• Delivery

• Installation

• OS deployment

• Application deployment

Weeks?

Page 12: Using Nagios with Chef

How did we get here?

Cloud or Virtual Deployment

• Purchasing

• Vendor build

• Delivery

• Installation

• OS deployment

• Application deployment

Nearly immediate

Page 13: Using Nagios with Chef

How did we get here?

Cloud or Virtual Deployment

• Purchasing

• Vendor build

• Delivery

• Installation

• OS deployment

• Application deployment

Nearly immediate

Must be fast

Page 14: Using Nagios with Chef

Why automate?

Good Reasons:

• More agility and faster scalability

• Improved infrastructure documentation

• Better disaster recovery

Page 15: Using Nagios with Chef

Why automate?

Good Reasons:

• More agility and faster scalability

• Improved infrastructure documentation

• Better disaster recovery

Really Good Reasons:

• Spend less time on monotonous tasks

• Spend more time solving interesting problems

Page 16: Using Nagios with Chef

Why automate?

Operations is responsible for two things:

Page 17: Using Nagios with Chef

Why automate?

Operations is responsible for two things:

1. Availability

Page 18: Using Nagios with Chef

Why automate?

Operations is responsible for two things:

1. Availability

2. Efficiency

Page 19: Using Nagios with Chef

What is Chef?

•Configuration management language

• Systems integration framework

•API for your infrastructure

http://www.flickr.com/photos/morville/3220961040/

Page 20: Using Nagios with Chef

Chef Principles

Page 21: Using Nagios with Chef

Chef Principles

•Idempotent

Page 22: Using Nagios with Chef

Chef Principles

•Idempotent

•Reasonable

Page 23: Using Nagios with Chef

Chef Principles

•Idempotent

•Reasonable

•Primitives

Page 24: Using Nagios with Chef

Chef Principles

•Idempotent

•Reasonable

•Primitives

•Scalable

Page 25: Using Nagios with Chef

Chef Principles

•Idempotent

•Reasonable

•Primitives

•Scalable

•Hackable

Page 26: Using Nagios with Chef

Chef Principles

•Idempotent

•Reasonable

•Primitives

•Scalable

•Hackable

•Shareable

Page 27: Using Nagios with Chef

Chef Basics

Chef manages Nodes

Page 28: Using Nagios with Chef

Chef Basics

Chef manages Nodes Nodes have Attributes

Page 29: Using Nagios with Chef

Chef Basics

Chef manages Nodes Nodes have AttributesUsers and Nodes authenticate as Clients

Page 30: Using Nagios with Chef

Chef Basics

Chef manages Nodes Nodes have AttributesUsers and Nodes authenticate as ClientsCookbooks contain Recipes

Page 31: Using Nagios with Chef

Chef Basics

Chef manages Nodes Nodes have AttributesUsers and Nodes authenticate as ClientsCookbooks contain RecipesEach node has a Run List

Page 32: Using Nagios with Chef

Chef Basics

Chef manages Nodes Nodes have AttributesUsers and Nodes authenticate as ClientsCookbooks contain RecipesEach node has a Run ListA Run List is a list of Recipes to run

Page 33: Using Nagios with Chef

Chef Basics

Chef manages Nodes Nodes have AttributesUsers and Nodes authenticate as ClientsCookbooks contain RecipesEach node has a Run ListA Run List is a list of Recipes to runA Role also has a Run List

Page 34: Using Nagios with Chef

Chef Basics

Chef manages Nodes Nodes have AttributesUsers and Nodes authenticate as ClientsCookbooks contain RecipesEach node has a Run ListA Run List is a list of Recipes to runA Role also has a Run ListRoles can also be added to a Node’s Run List

Page 35: Using Nagios with Chef

Chef Basics

Chef manages Nodes Nodes have AttributesUsers and Nodes authenticate as ClientsCookbooks contain RecipesEach node has a Run ListA Run List is a list of Recipes to runA Role also has a Run ListRoles can also be added to a Node’s Run ListNodes can be in Environments

Page 36: Using Nagios with Chef

Chef Basics

Chef manages Nodes Nodes have AttributesUsers and Nodes authenticate as ClientsCookbooks contain RecipesEach node has a Run ListA Run List is a list of Recipes to runA Role also has a Run ListRoles can also be added to a Node’s Run ListNodes can be in EnvironmentsData bags are... bags of data.

Page 37: Using Nagios with Chef

Chef Basics Visualized

node: srv03run_list: “role[db_server]”

role: web_serverrun_list: [“recipe[apache2]”, “recipe[php]” ]

role: db_serverrun_list: [ “recipe[mysql]”, “recipe[nfs]” ]

node: srv01run_list: “role[web_server]”

node: srv02run_list: “role[web_server]”

client: srv03client: srv01 client: srv02

Page 38: Using Nagios with Chef

Application Programming Interface

Give me an API or give me death.-- Andrew Clay Shafer (@littleidea)

The Meatcloud Manifesto

Page 39: Using Nagios with Chef

chef-shellknife

Chef Stacks

chef-client

Open Source Hosted Chef Private Chef

API

chef-solo

Page 40: Using Nagios with Chef

Chef 10 Open Source Architecture

Chef Expander

Page 41: Using Nagios with Chef

Resources

• A Resource is something you manageservice, package, file, user, execute, git

Page 42: Using Nagios with Chef

Resources

• A Resource is something you manageservice, package, file, user, execute, git

• Resources have actionsstart, install, create, deploy

• Resources can notify of other resources

Page 43: Using Nagios with Chef

Resources

• A Resource is something you manageservice, package, file, user, execute, git

• Resources have actionsstart, install, create, deploy

• Resources can notify of other resources

cookbook_file “/etc/apache2/apache2.conf” do source “apache2.conf” owner “root” group “root” mode 0644 notifies :restart, “service[apache2]”end

Page 44: Using Nagios with Chef

Providers

• A Provider performs the actions specified by the resource

Page 45: Using Nagios with Chef

Providers

• A Provider performs the actions specified by the resource

• Each Resource can have multiple providerspackage: apt, yum, macports...service: upstart, windows, systemd...

Page 46: Using Nagios with Chef

Providers

• A Provider performs the actions specified by the resource

• Each Resource can have multiple providerspackage: apt, yum, macports...service: upstart, windows, systemd...

• Each platform (OS) has default Providers that can be

package “sudo” do provider Chef::Provider::Package::Yum action :installend

Page 47: Using Nagios with Chef

A basic recipe

package “apache2” do action :installend

Page 48: Using Nagios with Chef

A basic recipe

package “apache2” do action :installend

service “apache2” do action :enableend

Page 49: Using Nagios with Chef

A basic recipe

package “apache2” do action :installend

service “apache2” do action :enableend

cookbook_file “/etc/apache2/apache2.conf” do source “apache2.conf” owner “root” group “root” mode 0644end

Page 50: Using Nagios with Chef

A basic recipe

package “apache2” do action :installend

service “apache2” do action :enableend

cookbook_file “/etc/apache2/apache2.conf” do source “apache2.conf” owner “root” group “root” mode 0644end

service “apache2” do action :startend

Page 51: Using Nagios with Chef

A basic recipe

package “apache2” do action :installend

service “apache2” do action :enable supports [ :restart, :reload, :status ]end

cookbook_file “/etc/apache2/apache2.conf” do source “apache2.conf” owner “root” group “root” mode 0644 notifies :restart, “service[apache2]”end

service “apache2” do action :startend

Page 52: Using Nagios with Chef

Search

# Find all nodes in production that are tagged ‘group_d’search(:node, “tags:group_d AND chef_environment:prod”)

# Find the mail server in this environmentsearch (:node, “role:mail_server AND chef_environment:corp”)

# Find all my nodes that run on HP hardwarenodes = search(:node, “dmi_systems_manufacturer:HP”)

# Dynamically create a config in a template<% nodes.each do |node| -%>server <%= node[‘hostname’] %><% end -%>

Search is a first class citizen

Search and Ruby are powerful allies

Page 53: Using Nagios with Chef

Nagios Demo•Download nagios server

cookbooks•Install nagios server•Create fake nodes

Page 54: Using Nagios with Chef

knife cookbook site install nagiosknife cookbook upload -acd chef-repoknife role from file monitoring.jsonknife data bag create usersknife data bag from file users btm.jsonknife node run list add chef-demo-server role[monitoring]sudo chef-client

http://chef-demo-server/nagios3/

for n in {1..5} ; do knife node from file fake${n}.json ; donesudo chef-client

knife data bag create nagios_hostgroupsknife data bag from file nagios_hostgroups hp_systems.jsonsudo chef-client

Page 55: Using Nagios with Chef

Questions?

There is lots more to learn about Chef at

http://