Adoptable Cookbooks List

Looking for a cookbook to adopt? You can now see a list of cookbooks available for adoption!
List of Adoptable Cookbooks

Supermarket Belongs to the Community

Supermarket belongs to the community. While Chef has the responsibility to keep it running and be stewards of its functionality, what it does and how it works is driven by the community. The chef/supermarket repository will continue to be where development of the Supermarket application takes place. Come be part of shaping the direction of Supermarket by opening issues and pull requests or by joining us on the Chef Mailing List.

Select Badges

Select Supported Platforms

RSS

op5_manage (9) Versions 0.8.0

Manage op5 hosts and services

Berkshelf
Policyfile
Knife
cookbook 'op5_manage', '= 0.8.0'
cookbook 'op5_manage', '= 0.8.0', :supermarket
knife cookbook site install op5_manage
knife cookbook site download op5_manage
README
Dependencies
Changelog
Quality 44%

op5_manage

  • Create, modify or remove hosts and services. Either from all your Chef nodes or from a single host.
  • Schedule down times for host objects.
  • Sophisticated caching is used to perform as less Api requests as possible.

All operations are performed using the restful op5 Api https://www.op5.com/explore-op5-monitor/features/op5-monitor-api/

Supported Platforms

  • CentOS 6, 7
  • Red Hat Enterprise Linux 6, 7
  • SuSE Linux Enterprise Server 11, 12

Configuration

op5 endpoints

An endpoint is all the information to connect to an op5 Api server. All of them are configured by attributes in the default.rb file. In addition sensitive credentials like username and password may stored in a Chef Vault. Only vaults of type client are supported.

Creating an endpoint vault

On your Chef build environment write your credentials to a JSON file. json { "op5_manage": { "endpoints": { "https://server.domain.tld/api": { "user": "Username", "password": "Pa$$w0rd" }, "https://other.endpoint.local/api": { "user": "Username", "password": "Pa$$w0rd" } } } }

Create the vault and import the data from file. The vault is named "op5_manage" and the item containing the credentials is named "endpoints". knife vault create op5_manage endpoints \ -A user1,user2 -S 'run_list:recipe\[op5_manage\:\:*\]' -M client -J ~/op5_endpoints.json

Changing the content of this vault item is easy. knife vault edit op5_manage endpoints

Configure attributes to use your vault instead of username and password. See attributes file default.rb for more information.

Order of run list

The op5_manage cookbook should be the last in run list.

Usage

Add a Chef node to op5 monitoring

The node.rb recipe is used to manage the current node. This is the common use case so you just have to add the default recipe to your run list. Without any configuration, host is created in op5 with a host group depending on your os. Use attributes to modify host parameters. Either in a recipe or in a role or environment (with JSON).

default['op5_manage']['node'] = {
    'hostgroups_add'    => [ 'hg_app_https_8443' ],
    'custom_variable'   => {
        '_API_PING_TXT' => 'OK',
        '_API_PING_URL' => '/artifactory/api/system/ping'
    },
    'services' => {
        'HTTPS URL API Ping' => {
            'template'            => 'alarm-template_business_processes',
            'check_command'       => 'check_https_url_string',
            'check_command_args'  => '"$_API_PING_URL$"!"$_API_PING_TXT$"',
            'notes_url'           => 'https://intranet.mydomain.tld/Monitoring#Checks-HTTPSURL',
            'action_url'          => 'https://$HOSTADDRESS$$_API_PING_URL$'
        }
    }
}
{
  "op5_manage": {
    "node": {
      "hostgroups_add": [ "hg_app_https_8443" ],
      "custom_variable": {
        "_API_PING_TXT": "OK",
        "_API_PING_URL": "/artifactory/api/system/ping"
      },
      "services": {
        "HTTPS URL API Ping": {
          "template":           "alarm-template_business_processes",
          "check_command":      "check_https_url_string",
          "check_command_args": "\"$_API_PING_URL$\"!\"$_API_PING_TXT$\"",
          "notes_url":          "https://intranet.mydomain.tld/Monitoring#Checks-HTTPS",
          "action_url":         "https://$HOSTADDRESS$$_API_PING_URL$"
        }
      }
    }
  }
}

Host groups

Typical host groups include - hg_app_https_8443 - hg_middleware_tomcat_8080 - hg_app_java

All hostgroups are listed here: https://demo.op5.com/monitor/index.php/listview/?q=%5Bhostgroups%5D%20all

Schedule host downtimes

The host_downtime.rb schedules various kinds of host downtimes. Please refer to op5 Api documentation for details. https://demo.op5.com/api/help/command/SCHEDULE_HOST_DOWNTIME https://demo.op5.com/api/help/command/SCHEDULE_AND_PROPAGATE_HOST_DOWNTIME https://demo.op5.com/api/help/command/SCHEDULE_AND_PROPAGATE_TRIGGERED_HOST_DOWNTIME

Downtimes are defined by attributes.

default['op5_manage']['host_downtimes'] = {
  'maintenance_artiprod-21.mydomain.tld' => {
    'command'     => 'SCHEDULE_HOST_DOWNTIME',
    'host_name'   => 'artiprod-21.mydomain.tld',
    'start_time'  => '23.10.2017 14:20',
    'end_time'    => '2017-10-23 14:24',
    'fixed'       => true,
    'duration'    => 0,
    'trigger_id'  => 0,
    'comment'     => 'Maintenance downtime for artiprod-21.mydomain.tld'
  }
}
{
  "op5_manage": {
    "host_downtimes": {
      "maintenance_artiprod-21.mydomain.tld": {
        "command": "SCHEDULE_HOST_DOWNTIME",
        "host_name": "artiprod-21.mydomain.tld",
        "start_time": "23.10.2017 23:00",
        "end_time": "2017-10-23 23:10",
        "fixed": false,
        "duration": 5,
        "trigger_id": 0,
        "comment": "Maintenance downtime for artiprod-21.mydomain.tld"
      }
    }
  }
}

Initial downtimes

Initial downtime recipe can be used to schedule a host downtime for newly provisioned servers. To prevent recipe from scheduling downtimes for existing servers, you can run knife command to set attribute.

knife exec -E "nodes.transform('name:dbsvrpip01-04.mydomain.tld') {|n| n.normal_attrs['op5_manage']['initial_downtime']['scheduled']=true  rescue nil }"
knife exec -E "nodes.transform('name:dbsvrpip01-04.mydomain.tld') {|n| n.normal_attrs['op5_manage'].delete('initial_downtime') rescue nil }"

knife exec -E "nodes.transform(:all) {|n| n.normal_attrs['op5_manage']['initial_downtime']['scheduled']=true  rescue nil }"

Troubleshoting

  • I recommend to use chef_hostname in your run list to avoid inconsistent state of hostname and node['fqdn'] after provisioning.
  • There is an open bug on caching host_downtimes. To work around you should never change the properties of an existing downtime. Also you must remove all downtimes in Chef before deleting the host on op5 server.
  • If you are looking for an issue it's a good advice to rename the cache file (/var/lib/op5_manage/cache.json) or temporary disable caching (node['op5_manage']['cache']['enabled'])

Attributes

<table> <tr> <th>Key</th> <th>Type</th> <th>Description</th> <th>Default</th> </tr> <tr> <td><tt>['op5_manage']['']</tt></td> <td>String</td> <td></td> <td><tt></tt></td> </tr> <tr> <td><tt>['endpoint']['url']</tt></td> <td>String</td> <td>URL of the op5 server</td> <td><tt>https://demo.op5.com/api</tt></td> </tr> <tr> <td><tt>['endpoint']['vault_name']</tt></td> <td>Symbol</td> <td>Use Chef Vault to overwrite user and password.<br/>Set to vault name or nil to not use vaults.</td> <td><tt>:op5_manage</tt></td> </tr> <tr> <td><tt>['endpoint']['vault_item']</tt></td> <td>String</td> <td>The item within the vault containing the endpoint credentials.</td> <td><tt>endpoints</tt></td> </tr> <tr> <td><tt>['endpoint']['tls_verify']</tt></td> <td>Bool</td> <td>If tls_verify is given and set to false, TLS server certificate validation is disabled. Use with caution!</td> <td><tt>true</tt></td> </tr> <tr> <td><tt>['endpoint']['proxy_addr']</tt></td> <td>String, Nil</td> <td>If not given, the ENVVAR http_proxy will be used.<br/>Set to nil (no proxy) or to valid FQDN to overwrite.</td> <td><tt>nil</tt></td> </tr> <tr> <td><tt>['endpoint']['proxy_port']</tt></td> <td>Integer, Nil</td> <td>Proxy port number. Only used if proxy_addr is given.</td> <td>Not given</td> </tr> <tr> <td><tt>['endpoint']['proxy_user']</tt></td> <td>String, Nil</td> <td>Proxy authentication</td> <td>Not given</td> </tr> <tr> <td><tt>['endpoint']['proxy_pass']</tt></td> <td>String, Nil</td> <td>Proxy authentication</td> <td>Not given</td> </tr> <tr> <td><tt>['endpoint_auth']['user']</tt></td> <td>String</td> <td>Username to access the API<br/>This may be overwriten by Chef Vault</td> <td><tt>op5chef-test$LDAP</tt></td> </tr> <tr> <td><tt>['endpoint_auth']['password']</tt></td> <td>String</td> <td>Password to access the API<br/>This may be overwriten by Chef Vault</td> <td><tt>*********</tt></td> </tr> <tr> <td><tt>['op5_manage']['cache']['enabled']</tt></td> <td>Bool</td> <td>Use caching</td> <td><tt>true</tt></td> </tr> <tr> <td><tt>['op5_manage']['cache']['path']</tt></td> <td>String</td> <td>Cache file</td> <td><tt>/var/lib/op5_manage/cache.json</tt></td> </tr> <tr> <td><tt>['op5_manage']['cache']['max_age']</tt></td> <td>String</td> <td>Seconds before configuration will be fetched from server again.</td> <td><tt>604800</tt></td> </tr> <tr> <td><tt>['op5_manage']['node']</tt></td> <td>Hash</td> <td>Manage local host</td> <td><tt></tt></td> </tr> <tr> <td><tt>['op5_manage']['hosts']</tt></td> <td>Hash</td> <td>Manage multiple services. See <a href="https://demo.op5.com/api/help/config/host">op5 Api host manual</a> for Api methods</td> <td>See service.rb attributes file</td> </tr> <tr> <td><tt>['op5_manage']['services']</tt></td> <td>Hash</td> <td>Manage multiple services. See <a href="https://demo.op5.com/api/help/config/host">op5 Api host manual</a> for Api methods</td> <td>See service.rb attributes file</td> </tr> <tr> <td><tt>['op5_manage']['host_downtimes']</tt></td> <td>Hash</td> <td>Schedule various kinds of host downtimes.</td> <td>See host.rb attributes file</td> </tr> </table>

License and Authors

Copyright 2016 Jakob Pfeiffer (pgp-jkp@pfeiffer.ws)

Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.

Dependent cookbooks

role_default >= 0.0.0
chef-vault >= 0.0.0

Contingent cookbooks

There are no cookbooks that are contingent upon this one.

0.1.3

  • Initial release of basic

0.2.0

  • New method host_config_eql? in op5_api_helper
  • Added idempotence to host actions :create and :remove
  • Ability to change the configuration of an already existing host

0.3.0

  • Creates, modifies and removes services. Services can only be bound to hosts but not to hostgroups.

0.4.0

  • Added node.rb recipe to manage host by host itself from their local machine.

0.5.0

  • Use Chef Vault to encrypt op5 endpoint credentials.

0.5.1

  • Replaced node.set by node default. Some documentation.

0.5.2

  • New helper recipe vault_handler.rb
  • New users for op5 test and prod
  • Test user password included in cookbook now for kitchen

0.5.3

  • Default action :create for hosts and services

0.5.4

  • Nodes can create extra services now
  • custom_variables renamed to custom_variable

0.5.5

  • README.md completed
  • Ready for production

0.5.6

  • Support for RHEL nodes

0.5.7

  • Fix RHEL support

0.5.8

  • Changed endpoint settings from node.run_state to default attribute
  • Moved endpoint authentication credentials to new node.run_state

0.5.9

  • Minor fixes
  • Documentation

0.6.0

  • Added order of run list and typical host groups to README

0.6.1

  • Workaround for bug ITB-19274 (comparison of Hash with Hash failed)
  • Replaced deprecated Fixnum by Interger
  • Better exception of Test Kitchen from vault_handling

0.6.2

  • Bugfix: removed is_volatile from node recipe

0.7.0

  • Final fix for embedded services in host config (ITB-19274)
  • New data structure in vault for better integration in shared items
  • Cache file now defaults to /var/lib/op5_manage/cache.json

0.8.0

  • New resource to schedule host downtimes
  • Recipe to schedule initial downtime right after server provisioning
  • Moved host attributes from attributes file to .kitchen.yml file
  • Services are managed by attributes instead of recipe now.

Collaborator Number Metric
            

0.8.0 failed this metric

Failure: Cookbook has 0 collaborators. A cookbook must have at least 2 collaborators to pass this metric.

Contributing File Metric
            

0.8.0 failed this metric

Failure: To pass this metric, your cookbook metadata must include a source url, the source url must be in the form of https://github.com/user/repo, and your repo must contain a CONTRIBUTING.md file

Foodcritic Metric
            

0.8.0 failed this metric

FC064: Ensure issues_url is set in metadata: op5_manage/metadata.rb:1
FC066: Ensure chef_version is set in metadata: op5_manage/metadata.rb:1
FC069: Ensure standardized license defined in metadata: op5_manage/metadata.rb:1
Run with Foodcritic Version 12.2.1 with tags metadata,correctness ~FC031 ~FC045 and failure tags any

License Metric
            

0.8.0 passed this metric

No Binaries Metric
            

0.8.0 passed this metric

Publish Metric
            

0.8.0 passed this metric

Supported Platforms Metric
            

0.8.0 passed this metric

Testing File Metric
            

0.8.0 failed this metric

Failure: To pass this metric, your cookbook metadata must include a source url, the source url must be in the form of https://github.com/user/repo, and your repo must contain a TESTING.md file

Version Tag Metric
            

0.8.0 failed this metric

Failure: To pass this metric, your cookbook metadata must include a source url, the source url must be in the form of https://github.com/user/repo, and your repo must include a tag that matches this cookbook version number