# See
# http://prefetch.net/code/domain-check
# http://www.cyberciti.biz/tips/howto-monitor-domain-expiration-renew-date.html
# http://www.cyberciti.biz/tips/domain-check-script.html
class domain {
  file { "/usr/local/bin/domain-check":
    ensure => present,
    owner   => "root",
    group   => "root",
    mode    => 755,
    source  => "puppet://$server/modules/nodo/bin/domain-check",
  }

  define check($interval = '60',  $email   = 'root', $hour = '0',
               $minute   = '0',   $weekday = '0',
               $file     = false, $ensure  = present) {

    $cert_check = "/usr/local/bin/domain-check -a -q -x ${interval} -e ${email}"

    case $file {
      true: {
        $command = "$cert_check -f ${file}"
      }
      false, default: {
        $command = "$cert_check -d ${name}"
      }
    }

    cron { "domain-check-${name}":
      command  => "$command >/dev/null 2>&1",
      user     => root,
      hour     => $hour,
      minute   => $minute,
      weekday  => $weekday,
      ensure   => $ensure,
      require  => File["/usr/local/bin/domain-check"],
    }
  }
}