From the official documentation:
NetBox can be configured via Event Rules to transmit outgoing webhooks to remote systems in response to internal object changes. The receiver can act on the data in these webhook messages to perform related tasks. Event rules can also execute custom scripts, enabling NetBox to run defined logic locally in response to object changes.
Example Usage
import * as pulumi from "@pulumi/pulumi";
import * as netbox from "@pulumi/netbox";
const test = new netbox.Webhook("test", {
name: "my-webhook",
payloadUrl: "https://example.com/webhook",
});
const webhook = new netbox.EventRule("webhook", {
name: "my-event-rule",
contentTypes: [
"dcim.site",
"virtualization.cluster",
],
actionType: "webhook",
actionObjectId: test.webhookId,
eventTypes: [
"object_created",
"object_updated",
"object_deleted",
"job_started",
"job_completed",
"job_failed",
"job_errored",
],
});
const script = new netbox.EventRule("script", {
name: "my-script-event-rule",
contentTypes: ["dcim.site"],
actionType: "script",
actionObjectId: 42,
eventTypes: ["object_created"],
});
import pulumi
import pulumi_netbox as netbox
test = netbox.Webhook("test",
name="my-webhook",
payload_url="https://example.com/webhook")
webhook = netbox.EventRule("webhook",
name="my-event-rule",
content_types=[
"dcim.site",
"virtualization.cluster",
],
action_type="webhook",
action_object_id=test.webhook_id,
event_types=[
"object_created",
"object_updated",
"object_deleted",
"job_started",
"job_completed",
"job_failed",
"job_errored",
])
script = netbox.EventRule("script",
name="my-script-event-rule",
content_types=["dcim.site"],
action_type="script",
action_object_id=42,
event_types=["object_created"])
package main
import (
"github.com/pulumi/pulumi-terraform-provider/sdks/go/netbox/v5/netbox"
"github.com/pulumi/pulumi/sdk/v3/go/pulumi"
)
func main() {
pulumi.Run(func(ctx *pulumi.Context) error {
test, err := netbox.NewWebhook(ctx, "test", &netbox.WebhookArgs{
Name: pulumi.String("my-webhook"),
PayloadUrl: pulumi.String("https://example.com/webhook"),
})
if err != nil {
return err
}
_, err = netbox.NewEventRule(ctx, "webhook", &netbox.EventRuleArgs{
Name: pulumi.String("my-event-rule"),
ContentTypes: pulumi.StringArray{
pulumi.String("dcim.site"),
pulumi.String("virtualization.cluster"),
},
ActionType: pulumi.String("webhook"),
ActionObjectId: test.WebhookId,
EventTypes: pulumi.StringArray{
pulumi.String("object_created"),
pulumi.String("object_updated"),
pulumi.String("object_deleted"),
pulumi.String("job_started"),
pulumi.String("job_completed"),
pulumi.String("job_failed"),
pulumi.String("job_errored"),
},
})
if err != nil {
return err
}
_, err = netbox.NewEventRule(ctx, "script", &netbox.EventRuleArgs{
Name: pulumi.String("my-script-event-rule"),
ContentTypes: pulumi.StringArray{
pulumi.String("dcim.site"),
},
ActionType: pulumi.String("script"),
ActionObjectId: pulumi.Float64(42),
EventTypes: pulumi.StringArray{
pulumi.String("object_created"),
},
})
if err != nil {
return err
}
return nil
})
}
using System.Collections.Generic;
using System.Linq;
using Pulumi;
using Netbox = Pulumi.Netbox;
return await Deployment.RunAsync(() =>
{
var test = new Netbox.Webhook("test", new()
{
Name = "my-webhook",
PayloadUrl = "https://example.com/webhook",
});
var webhook = new Netbox.EventRule("webhook", new()
{
Name = "my-event-rule",
ContentTypes = new[]
{
"dcim.site",
"virtualization.cluster",
},
ActionType = "webhook",
ActionObjectId = test.WebhookId,
EventTypes = new[]
{
"object_created",
"object_updated",
"object_deleted",
"job_started",
"job_completed",
"job_failed",
"job_errored",
},
});
var script = new Netbox.EventRule("script", new()
{
Name = "my-script-event-rule",
ContentTypes = new[]
{
"dcim.site",
},
ActionType = "script",
ActionObjectId = 42,
EventTypes = new[]
{
"object_created",
},
});
});
package generated_program;
import com.pulumi.Context;
import com.pulumi.Pulumi;
import com.pulumi.core.Output;
import com.pulumi.netbox.Webhook;
import com.pulumi.netbox.WebhookArgs;
import com.pulumi.netbox.EventRule;
import com.pulumi.netbox.EventRuleArgs;
import java.util.List;
import java.util.ArrayList;
import java.util.Map;
import java.io.File;
import java.nio.file.Files;
import java.nio.file.Paths;
public class App {
public static void main(String[] args) {
Pulumi.run(App::stack);
}
public static void stack(Context ctx) {
var test = new Webhook("test", WebhookArgs.builder()
.name("my-webhook")
.payloadUrl("https://example.com/webhook")
.build());
var webhook = new EventRule("webhook", EventRuleArgs.builder()
.name("my-event-rule")
.contentTypes(
"dcim.site",
"virtualization.cluster")
.actionType("webhook")
.actionObjectId(test.webhookId())
.eventTypes(
"object_created",
"object_updated",
"object_deleted",
"job_started",
"job_completed",
"job_failed",
"job_errored")
.build());
var script = new EventRule("script", EventRuleArgs.builder()
.name("my-script-event-rule")
.contentTypes("dcim.site")
.actionType("script")
.actionObjectId(42.0)
.eventTypes("object_created")
.build());
}
}
resources:
test:
type: netbox:Webhook
properties:
name: my-webhook
payloadUrl: https://example.com/webhook
webhook:
type: netbox:EventRule
properties:
name: my-event-rule
contentTypes:
- dcim.site
- virtualization.cluster
actionType: webhook
actionObjectId: ${test.webhookId}
eventTypes:
- object_created
- object_updated
- object_deleted
- job_started
- job_completed
- job_failed
- job_errored
script:
type: netbox:EventRule
properties:
name: my-script-event-rule
contentTypes:
- dcim.site
actionType: script
actionObjectId: 42 # existing NetBox Script ID
eventTypes:
- object_created
Create EventRule Resource
Resources are created with functions called constructors. To learn more about declaring and configuring resources, see Resources.
Constructor syntax
new EventRule(name: string, args: EventRuleArgs, opts?: CustomResourceOptions);@overload
def EventRule(resource_name: str,
args: EventRuleArgs,
opts: Optional[ResourceOptions] = None)
@overload
def EventRule(resource_name: str,
opts: Optional[ResourceOptions] = None,
action_object_id: Optional[float] = None,
action_type: Optional[str] = None,
content_types: Optional[Sequence[str]] = None,
event_types: Optional[Sequence[str]] = None,
conditions: Optional[str] = None,
description: Optional[str] = None,
enabled: Optional[bool] = None,
event_rule_id: Optional[str] = None,
name: Optional[str] = None,
tags: Optional[Sequence[str]] = None)func NewEventRule(ctx *Context, name string, args EventRuleArgs, opts ...ResourceOption) (*EventRule, error)public EventRule(string name, EventRuleArgs args, CustomResourceOptions? opts = null)
public EventRule(String name, EventRuleArgs args)
public EventRule(String name, EventRuleArgs args, CustomResourceOptions options)
type: netbox:EventRule
properties: # The arguments to resource properties.
options: # Bag of options to control resource's behavior.
Parameters
- name string
- The unique name of the resource.
- args EventRuleArgs
- The arguments to resource properties.
- opts CustomResourceOptions
- Bag of options to control resource's behavior.
- resource_name str
- The unique name of the resource.
- args EventRuleArgs
- The arguments to resource properties.
- opts ResourceOptions
- Bag of options to control resource's behavior.
- ctx Context
- Context object for the current deployment.
- name string
- The unique name of the resource.
- args EventRuleArgs
- The arguments to resource properties.
- opts ResourceOption
- Bag of options to control resource's behavior.
- name string
- The unique name of the resource.
- args EventRuleArgs
- The arguments to resource properties.
- opts CustomResourceOptions
- Bag of options to control resource's behavior.
- name String
- The unique name of the resource.
- args EventRuleArgs
- The arguments to resource properties.
- options CustomResourceOptions
- Bag of options to control resource's behavior.
Constructor example
The following reference example uses placeholder values for all input properties.
var eventRuleResource = new Netbox.EventRule("eventRuleResource", new()
{
ActionObjectId = 0,
ActionType = "string",
ContentTypes = new[]
{
"string",
},
EventTypes = new[]
{
"string",
},
Conditions = "string",
Description = "string",
Enabled = false,
EventRuleId = "string",
Name = "string",
Tags = new[]
{
"string",
},
});
example, err := netbox.NewEventRule(ctx, "eventRuleResource", &netbox.EventRuleArgs{
ActionObjectId: pulumi.Float64(0),
ActionType: pulumi.String("string"),
ContentTypes: pulumi.StringArray{
pulumi.String("string"),
},
EventTypes: pulumi.StringArray{
pulumi.String("string"),
},
Conditions: pulumi.String("string"),
Description: pulumi.String("string"),
Enabled: pulumi.Bool(false),
EventRuleId: pulumi.String("string"),
Name: pulumi.String("string"),
Tags: pulumi.StringArray{
pulumi.String("string"),
},
})
var eventRuleResource = new EventRule("eventRuleResource", EventRuleArgs.builder()
.actionObjectId(0.0)
.actionType("string")
.contentTypes("string")
.eventTypes("string")
.conditions("string")
.description("string")
.enabled(false)
.eventRuleId("string")
.name("string")
.tags("string")
.build());
event_rule_resource = netbox.EventRule("eventRuleResource",
action_object_id=0,
action_type="string",
content_types=["string"],
event_types=["string"],
conditions="string",
description="string",
enabled=False,
event_rule_id="string",
name="string",
tags=["string"])
const eventRuleResource = new netbox.EventRule("eventRuleResource", {
actionObjectId: 0,
actionType: "string",
contentTypes: ["string"],
eventTypes: ["string"],
conditions: "string",
description: "string",
enabled: false,
eventRuleId: "string",
name: "string",
tags: ["string"],
});
type: netbox:EventRule
properties:
actionObjectId: 0
actionType: string
conditions: string
contentTypes:
- string
description: string
enabled: false
eventRuleId: string
eventTypes:
- string
name: string
tags:
- string
EventRule Resource Properties
To learn more about resource properties and how to use them, see Inputs and Outputs in the Architecture and Concepts docs.
Inputs
In Python, inputs that are objects can be passed either as argument classes or as dictionary literals.
The EventRule resource accepts the following input properties:
- Action
Object doubleId - Action
Type string - Valid values are
webhookandscript. - Content
Types List<string> - Event
Types List<string> - The types of event which will trigger this rule. By default, valid values are
object_created,oject_updated,object_deleted,job_started,job_completed,job_failedandjob_errored. - Conditions string
- Description string
- Enabled bool
- Defaults to
true. - Event
Rule stringId - The ID of this resource.
- Name string
- List<string>
- Action
Object float64Id - Action
Type string - Valid values are
webhookandscript. - Content
Types []string - Event
Types []string - The types of event which will trigger this rule. By default, valid values are
object_created,oject_updated,object_deleted,job_started,job_completed,job_failedandjob_errored. - Conditions string
- Description string
- Enabled bool
- Defaults to
true. - Event
Rule stringId - The ID of this resource.
- Name string
- []string
- action
Object DoubleId - action
Type String - Valid values are
webhookandscript. - content
Types List<String> - event
Types List<String> - The types of event which will trigger this rule. By default, valid values are
object_created,oject_updated,object_deleted,job_started,job_completed,job_failedandjob_errored. - conditions String
- description String
- enabled Boolean
- Defaults to
true. - event
Rule StringId - The ID of this resource.
- name String
- List<String>
- action
Object numberId - action
Type string - Valid values are
webhookandscript. - content
Types string[] - event
Types string[] - The types of event which will trigger this rule. By default, valid values are
object_created,oject_updated,object_deleted,job_started,job_completed,job_failedandjob_errored. - conditions string
- description string
- enabled boolean
- Defaults to
true. - event
Rule stringId - The ID of this resource.
- name string
- string[]
- action_
object_ floatid - action_
type str - Valid values are
webhookandscript. - content_
types Sequence[str] - event_
types Sequence[str] - The types of event which will trigger this rule. By default, valid values are
object_created,oject_updated,object_deleted,job_started,job_completed,job_failedandjob_errored. - conditions str
- description str
- enabled bool
- Defaults to
true. - event_
rule_ strid - The ID of this resource.
- name str
- Sequence[str]
- action
Object NumberId - action
Type String - Valid values are
webhookandscript. - content
Types List<String> - event
Types List<String> - The types of event which will trigger this rule. By default, valid values are
object_created,oject_updated,object_deleted,job_started,job_completed,job_failedandjob_errored. - conditions String
- description String
- enabled Boolean
- Defaults to
true. - event
Rule StringId - The ID of this resource.
- name String
- List<String>
Outputs
All input properties are implicitly available as output properties. Additionally, the EventRule resource produces the following output properties:
- Id string
- The provider-assigned unique ID for this managed resource.
- List<string>
- Id string
- The provider-assigned unique ID for this managed resource.
- []string
- id String
- The provider-assigned unique ID for this managed resource.
- List<String>
- id string
- The provider-assigned unique ID for this managed resource.
- string[]
- id str
- The provider-assigned unique ID for this managed resource.
- Sequence[str]
- id String
- The provider-assigned unique ID for this managed resource.
- List<String>
Look up Existing EventRule Resource
Get an existing EventRule resource’s state with the given name, ID, and optional extra properties used to qualify the lookup.
public static get(name: string, id: Input<ID>, state?: EventRuleState, opts?: CustomResourceOptions): EventRule@staticmethod
def get(resource_name: str,
id: str,
opts: Optional[ResourceOptions] = None,
action_object_id: Optional[float] = None,
action_type: Optional[str] = None,
conditions: Optional[str] = None,
content_types: Optional[Sequence[str]] = None,
description: Optional[str] = None,
enabled: Optional[bool] = None,
event_rule_id: Optional[str] = None,
event_types: Optional[Sequence[str]] = None,
name: Optional[str] = None,
tags: Optional[Sequence[str]] = None,
tags_alls: Optional[Sequence[str]] = None) -> EventRulefunc GetEventRule(ctx *Context, name string, id IDInput, state *EventRuleState, opts ...ResourceOption) (*EventRule, error)public static EventRule Get(string name, Input<string> id, EventRuleState? state, CustomResourceOptions? opts = null)public static EventRule get(String name, Output<String> id, EventRuleState state, CustomResourceOptions options)resources: _: type: netbox:EventRule get: id: ${id}- name
- The unique name of the resulting resource.
- id
- The unique provider ID of the resource to lookup.
- state
- Any extra arguments used during the lookup.
- opts
- A bag of options that control this resource's behavior.
- resource_name
- The unique name of the resulting resource.
- id
- The unique provider ID of the resource to lookup.
- name
- The unique name of the resulting resource.
- id
- The unique provider ID of the resource to lookup.
- state
- Any extra arguments used during the lookup.
- opts
- A bag of options that control this resource's behavior.
- name
- The unique name of the resulting resource.
- id
- The unique provider ID of the resource to lookup.
- state
- Any extra arguments used during the lookup.
- opts
- A bag of options that control this resource's behavior.
- name
- The unique name of the resulting resource.
- id
- The unique provider ID of the resource to lookup.
- state
- Any extra arguments used during the lookup.
- opts
- A bag of options that control this resource's behavior.
- Action
Object doubleId - Action
Type string - Valid values are
webhookandscript. - Conditions string
- Content
Types List<string> - Description string
- Enabled bool
- Defaults to
true. - Event
Rule stringId - The ID of this resource.
- Event
Types List<string> - The types of event which will trigger this rule. By default, valid values are
object_created,oject_updated,object_deleted,job_started,job_completed,job_failedandjob_errored. - Name string
- List<string>
- List<string>
- Action
Object float64Id - Action
Type string - Valid values are
webhookandscript. - Conditions string
- Content
Types []string - Description string
- Enabled bool
- Defaults to
true. - Event
Rule stringId - The ID of this resource.
- Event
Types []string - The types of event which will trigger this rule. By default, valid values are
object_created,oject_updated,object_deleted,job_started,job_completed,job_failedandjob_errored. - Name string
- []string
- []string
- action
Object DoubleId - action
Type String - Valid values are
webhookandscript. - conditions String
- content
Types List<String> - description String
- enabled Boolean
- Defaults to
true. - event
Rule StringId - The ID of this resource.
- event
Types List<String> - The types of event which will trigger this rule. By default, valid values are
object_created,oject_updated,object_deleted,job_started,job_completed,job_failedandjob_errored. - name String
- List<String>
- List<String>
- action
Object numberId - action
Type string - Valid values are
webhookandscript. - conditions string
- content
Types string[] - description string
- enabled boolean
- Defaults to
true. - event
Rule stringId - The ID of this resource.
- event
Types string[] - The types of event which will trigger this rule. By default, valid values are
object_created,oject_updated,object_deleted,job_started,job_completed,job_failedandjob_errored. - name string
- string[]
- string[]
- action_
object_ floatid - action_
type str - Valid values are
webhookandscript. - conditions str
- content_
types Sequence[str] - description str
- enabled bool
- Defaults to
true. - event_
rule_ strid - The ID of this resource.
- event_
types Sequence[str] - The types of event which will trigger this rule. By default, valid values are
object_created,oject_updated,object_deleted,job_started,job_completed,job_failedandjob_errored. - name str
- Sequence[str]
- Sequence[str]
- action
Object NumberId - action
Type String - Valid values are
webhookandscript. - conditions String
- content
Types List<String> - description String
- enabled Boolean
- Defaults to
true. - event
Rule StringId - The ID of this resource.
- event
Types List<String> - The types of event which will trigger this rule. By default, valid values are
object_created,oject_updated,object_deleted,job_started,job_completed,job_failedandjob_errored. - name String
- List<String>
- List<String>
Package Details
- Repository
- netbox e-breuninger/terraform-provider-netbox
- License
- Notes
- This Pulumi package is based on the
netboxTerraform Provider.
