puppet のレポーティング

puppet には実行結果をレポートする機能がある。

目次

  1. レポート用の設定
    1. クライアント側の設定
    2. サーバ側の設定
  2. レポートの種類
    1. tagmail
    2. rrdgraph
    3. store
    4. log
  3. 関連ページ

レポート用の設定

クライアント側の設定

puppetd 起動時に --report オプションをつける。

$ puppetd --report

または、/etc/puppet/puppetd.conf で以下の設定をしておけば、--report オプションはいらない。

[puppetd]
    report = true

サーバ側の設定

puppetmasterd 起動時に --reports オプションでレポートタイプを指定する。

$ puppetmasterd --reports tagmail,daily,security

または、/etc/puppet/puppetmasterd.conf で以下の設定をしておけば、--reports オプションはいらない。

[puppetmasterd]
    reports = tagmail,daily,security

また、/etc/puppet/namespaceauth.conf で以下の設定も必要。

[puppetreports]
    allow *.southpark

レポートの種類

tagmail

レポートをメールで飛ばす。

こんな感じのメールが飛んでくる。

To: root@mizzy.org
Subject: Puppet Report for cartman.southpark
From: report@kenny.southpark
Date: Sun, 25 Mar 2007 14:21:30 +0900 (JST)

Sun Mar 25 14:21:30 +0900 2007 //Exec[test]/returns (notice): executed successfully

宛先の設定

宛先の設定は /etc/puppet/tagmail.conf で行う。puppet にはタギング機能があって、タグ毎に宛先を変えられる。all はすべてのタグに適用される。(タギング機能はいつか説明する。)

all:  root@localhost
mail: postmaster@domain.com
sun:  solarisadmins@domain.com

その他の設定

sendmail のパス、From アドレスの設定、SMTP サーバの設定は /etc/puppet/puppetmasterd.conf で行う。(オプショナル)

[puppetmasterd]
    sendmail   = /usr/lib/sendmail
    reportfrom = puppet@localhost
    smtpserver = localhost

rrdgraph

グラフ出力してくれるらしいが、うまく動作させることができてないので、詳細不明。

この辺りは入れる必要があるっぽい。

store

クライアント毎にディレクトリが作られ、その下に yaml ファイルが生成される。

$ ls /var/puppet/reports/cartman.southpark/
200703250451.yaml  200703250457.yaml  200703250521.yaml
200703250452.yaml  200703250520.yaml  200703250528.yaml 

PuppetShow が利用するためのデータを吐き出すのが目的らしい。

yaml の中身は Puppet::Transaction::Report オブジェクトをダンプしたもののようだ。

--- !ruby/object:Puppet::Transaction::Report
host: cartman.southpark
logs:
- !ruby/object:Puppet::Util::Log
  level: :notice
  message: executed successfully
  objectsource: true
  source: //Exec[test]/returns
  tags:
  - :main
  - :exec
  - :returns
  time: 2007-03-25 13:50:59.891126 +09:00
metrics:
  time: !ruby/object:Puppet::Util::Metric
    label: Time
    name: time
    values:
    - - :total
      - Total
      - 0.810036182403564
    - - :config_retrieval
      - Config retrieval
      - 0.798027038574219
  resources: !ruby/object:Puppet::Util::Metric
    label: Resources
    name: resources
    values:
    - - :restarted
      - Restarted
      - 0
    - - :scheduled
      - Scheduled
      - 1
    - - :out_of_sync
      - Out of sync
      - 1
    - - :failed
      - Failed
      - 0 
    - - :failed_restarts
      - Failed restarts
      - 0
    - - :applied
      - Applied
      - 1
    - - :total
      - Total
      - 3
    - - :skipped
      - Skipped
      - 0
  changes: !ruby/object:Puppet::Util::Metric
    label: Changes
    name: changes
    values:
    - - :total
      - Total
      - 1
records: {}

time: 2007-03-25 13:50:59.912694 +09:00     

log

syslog に以下の様にログ出力される。

Apr 29 00:24:30 kenny puppetmasterd[8341]: Compiled configuration for cartman.southpark in 0.02 seconds
Apr 29 00:24:38 kenny puppetmasterd[8341]: (//cartman.southpark/southpark/httpd[httpd settings]/Exec[httpd restart]/returns) executed successfully
Apr 29 00:24:38 kenny puppetmasterd[8341]: (//cartman.southpark/southpark/httpd[httpd settings]/File[/etc/httpd/conf.d]/checksum) checksum changed '{time}Sat Mar 24 22:07:29 JST 2007' to '{time}Sun Apr 29 00:15:29 JST 2007'
Apr 29 00:24:38 kenny puppetmasterd[8341]: (//Exec[test]/returns) executed successfully

設定ファイル中の syslogfacility で syslog facility が変更可能。デフォルトは daemon 。

存在しないコマンドをマニフェストで指定してわざとエラーを起こしてみたら、/var/log/syslog の方にエラーが出力された。

Apr 30 01:10:06 kenny puppetmasterd[13566]: (//cartman.southpark/southpark/httpd[httpd settings]/Exec[httpd restart]) Failed to call refresh on
Exec[httpd restart]: ftouch /tmp/puppet returned 1 instead of 0 at /home/miya/etc/puppet/site.pp:13

関連ページ