From 767eac9dbdbc0916e27ca9a423713069a9145370 Mon Sep 17 00:00:00 2001 From: Peter Palfrader Date: Sun, 9 Oct 2011 11:22:37 +0200 Subject: [PATCH] Better motd on kvm hosts --- manifests/site.pp | 2 +- modules/motd/templates/motd.erb | 41 ++++++++++++++++++++++++++++----- 2 files changed, 36 insertions(+), 7 deletions(-) diff --git a/manifests/site.pp b/manifests/site.pp index 6c7ec54d0..3c862097c 100644 --- a/manifests/site.pp +++ b/manifests/site.pp @@ -16,7 +16,7 @@ Exec { node default { $localinfo = yamlinfo('*', "/etc/puppet/modules/debian-org/misc/local.yaml") $nodeinfo = nodeinfo($fqdn, "/etc/puppet/modules/debian-org/misc/local.yaml") - $allnodeinfo = allnodeinfo("sshRSAHostKey ipHostNumber", "purpose mXRecord") + $allnodeinfo = allnodeinfo("sshRSAHostKey ipHostNumber", "purpose mXRecord physicalHost purpose") notice( sprintf("hoster for %s is %s", $fqdn, getfromhash($nodeinfo, 'hoster', 'name') ) ) include munin-node diff --git a/modules/motd/templates/motd.erb b/modules/motd/templates/motd.erb index e4fb77f75..636cdb64b 100644 --- a/modules/motd/templates/motd.erb +++ b/modules/motd/templates/motd.erb @@ -11,6 +11,16 @@ def wrap(s, width=78) s.gsub(/(.{1,#{width}})(\s+|\Z)/, "\\1\n") end +def markup(l) + if l =~ /\[\[(\*|-)?(.*?)\]\]/ + l = $2 + end + if l =~ /\[\[(.*?)\|(.*?)\]\]/ + l = $2 + end + return l +end + purp = '' if nodeinfo.has_key?('nameinfo') purp += wrap(nodeinfo['nameinfo']) + "\n\n" @@ -39,12 +49,7 @@ if (nodeinfo['ldap'].has_key?('purpose')) else purp += ", used for the following services:\n" nodeinfo['ldap']['purpose'].sort.each do |l| - if l =~ /\[\[(\*|-)?(.*?)\]\]/ - l = $2 - end - if l =~ /\[\[(.*?)\|(.*?)\]\]/ - l = $2 - end + l = markup(l) purp += "\t" + l + "\n" end end @@ -56,6 +61,30 @@ if (nodeinfo['ldap'].has_key?('physicalHost')) purp += "\nThis virtual server runs on the physical host #{nodeinfo['ldap']['physicalHost'][0]}.\n" end + +vms = [] +allnodeinfo.keys.sort.each do |node| + if allnodeinfo[node]['physicalHost'] and allnodeinfo[node]['physicalHost'].include?(fqdn) + vms << node + end +end +unless vms.empty? + purp += "\nThe following virtual machines run on this system:\n" + vms.each do |node| + purp += "\t#{node}" + if allnodeinfo[node]['purpose'] + purp += ":\n" + allnodeinfo[node]['purpose'].sort.each do |l| + l = markup(l) + purp += "\t - " + l + "\n" + end + else + purp += "\n" + end + end +end + + if nodeinfo.has_key?('footer') purp += "\n" + wrap(nodeinfo['footer']) + "\n" end -- 2.20.1