Extending a defined type

63 views
Skip to first unread message

Angel L. Mateo

unread,
Sep 8, 2016, 7:54:07 AM9/8/16
to puppet...@googlegroups.com
Hi,

I would like to add to existing nagios_* types the possibility to
define custom variables
(https://assets.nagios.com/downloads/nagioscore/docs/nagioscore/3/en/customobjectvars.html).

I have found a few tickets like
https://tickets.puppetlabs.com/browse/PUP-1067 or
https://tickets.puppetlabs.com/browse/PUP-1075 but it seems there are
blocked.

So I'm thinking the possibility to create my own types extending them.
Is there any documentation about extending types. All documentation I
have found is about creating a completely new type, but I haven't found
any about inheriting an existing one.

--
Angel L. Mateo Martínez
Sección de Telemática
Área de Tecnologías de la Información
y las Comunicaciones Aplicadas (ATICA)
http://www.um.es/atica
Tfo: 868889150
Fax: 868888337

Matthew Pounsett

unread,
Sep 8, 2016, 10:49:59 AM9/8/16
to Puppet Users


On Thursday, 8 September 2016 07:54:07 UTC-4, amateo wrote:

        So I'm thinking the possibility to create my own types extending them.
Is there any documentation about extending types. All documentation I
have found is about creating a completely new type, but I haven't found
any about inheriting an existing one.


You can fairly easily extend a resource or type by wrapping it in a new one of your own making.  The concept is similar to inheritance in object oriented languages, but the mechanism is a little less sleek.

I'm picking a resource with a small list of attributes to keep the example simple, but you can do this with anything.

define my_notify (
  $name    
=> $title,
  $message  
=> undef,
  $withpath
=> undef,
  $my_notify_special
,
){
 
# do custom things here
  notify
{ $title:
    name    
=> $name,
    message  
=> $message,
    withpath
=> $withpath,
 
}
 
# do more custom things here, maybe with $my_notify_special
}


Angel L. Mateo

unread,
Sep 9, 2016, 3:21:59 AM9/9/16
to puppet...@googlegroups.com
El 08/09/16 a las 16:49, Matthew Pounsett escribió:
>
>
> On Thursday, 8 September 2016 07:54:07 UTC-4, amateo wrote:
>
>
> So I'm thinking the possibility to create my own types
> extending them.
> Is there any documentation about extending types. All documentation I
> have found is about creating a completely new type, but I haven't found
> any about inheriting an existing one.
>
I'm not sure I can do what we want with a define. I want to add a
property to the nagios_* types so I can define custom variables in
nagios objects. Since the actual nagios object is handle with puppet
types, I think the define is not appropriate for this.
Reply all
Reply to author
Forward
0 new messages