Nagios user lookup

21 views
Skip to first unread message

Jonathan Gazeley

unread,
Dec 22, 2014, 10:27:47 AM12/22/14
to puppet-users
Hi folks,

I'm not sure if I'm thinking about the problem the wrong way, but I'm trying to design a way to have one directory of user information in hiera which feeds the creation of unix users as well as nagios contacts. I have a hiera data structure like this:

unifiedusers:
  jon:
    nagiosuser: true
    comment: Jonathan
    gid: resnet
    uid: 56933
    sudo: true
    groups:
      - resnet
      - superadmins
  paul:
    nagiosuser: true
    comment: Paul
    gid: resnet
    uid: 23770
    sudo: true
    groups:
      - resnet
      - superadmins
  dave:
    nagiosuser: false
    comment: Dave
    gid: networks
    uid: 1234
    sudo: false
    groups:
      - resnet

I have code that works well to create unix users & groups. I'm struggling more with nagios stuff. Ideally I want to end up with an array of usernames for whom nagiosuser==true. So my array @nagiosusers would contain ['jon', 'paul'] but not 'dave'. Is this possible?

Thanks,
Jonathan

jcbollinger

unread,
Dec 23, 2014, 9:26:31 AM12/23/14
to puppet...@googlegroups.com
Of course it's possible.  Puppet has enough hooks that you can plug in any kind of data transformation you want.

Puppet does not have a direct solution to this particular problem, however.  It would be cleanest to write a custom function to do what this job, but it would be quicker to do it with an inline template (which you can consider a proof of concept for that function) something like this:

    $nagios_users_string = inline_template("<%= @unifiedusers.select { |k, v| v['nagiosuser'] }.keys.join(',') %>")
    $nagios_users = split($nagios_users_string, ',')


John

Reply all
Reply to author
Forward
0 new messages