├── docker ├── .MYSQL_PASSWORD ├── .MYSQL_USER ├── .MYSQL_ROOT_PASSWORD ├── .env_db_mysql ├── .env_web ├── .env_srv └── docker-compose.yml ├── .gitignore ├── go.mod ├── main.go ├── templates └── index.md.tmpl ├── examples └── provider │ └── provider.tf ├── docs ├── data-sources │ ├── proxy.md │ ├── hostgroup.md │ ├── application.md │ ├── template.md │ └── host.md ├── resources │ ├── hostgroup.md │ ├── application.md │ ├── template.md │ ├── trigger.md │ ├── proto_trigger.md │ ├── item_snmptrap.md │ ├── item_trapper.md │ ├── item_aggregate.md │ ├── item_dependent.md │ ├── proto_item_trapper.md │ ├── proto_item_snmptrap.md │ ├── item_calculated.md │ ├── item_simple.md │ ├── item_external.md │ ├── item_internal.md │ ├── proto_item_aggregate.md │ ├── proto_item_dependent.md │ ├── item_agent.md │ ├── proto_item_calculated.md │ ├── proto_item_simple.md │ ├── proto_item_external.md │ ├── proto_item_internal.md │ ├── proto_item_agent.md │ ├── graph.md │ ├── proto_graph.md │ ├── lld_trapper.md │ ├── lld_simple.md │ ├── lld_external.md │ ├── lld_internal.md │ ├── lld_dependent.md │ ├── lld_agent.md │ ├── item_snmp.md │ ├── proto_item_snmp.md │ ├── item_http.md │ ├── proto_item_http.md │ ├── lld_snmp.md │ ├── lld_http.md │ └── host.md └── index.md ├── provider ├── log.go ├── provider_test.go ├── resource_snmptrap_common.go ├── resource_aggregate_common.go ├── utils.go ├── common_macro.go ├── resource_proxy.go ├── resource_calculated_common.go ├── resource_trapper_common.go ├── resource_host_test.go ├── resource_simple_common.go ├── resource_external_common.go ├── resource_internal_common.go ├── resource_dependent_common.go ├── resource_agent_common.go ├── resource_hostgroup.go ├── resource_application.go ├── provider.go ├── resource_template.go ├── resource_trigger.go ├── resource_snmp_common.go ├── resource_http_common.go ├── common_item.go └── common_lld.go ├── LICENSE ├── .github └── workflows │ └── release.yml ├── .goreleaser.yml └── example.tf /docker/.MYSQL_PASSWORD: -------------------------------------------------------------------------------- 1 | zabbix -------------------------------------------------------------------------------- /docker/.MYSQL_USER: -------------------------------------------------------------------------------- 1 | zabbix -------------------------------------------------------------------------------- /docker/.MYSQL_ROOT_PASSWORD: -------------------------------------------------------------------------------- 1 | root_pwd -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | terraform-provider-zabbix 2 | .terraform 3 | crash.log 4 | terraform.tfstate 5 | terraform.tfstate.backup 6 | docker/zbx_env 7 | -------------------------------------------------------------------------------- /go.mod: -------------------------------------------------------------------------------- 1 | module github.com/tpretz/terraform-provider-zabbix 2 | 3 | go 1.11 4 | 5 | require ( 6 | github.com/hashicorp/terraform v0.12.23 7 | github.com/hashicorp/terraform-plugin-sdk v1.7.0 8 | github.com/tpretz/go-zabbix-api v0.16.0 9 | ) 10 | 11 | //replace github.com/tpretz/go-zabbix-api => ../go-zabbix-api 12 | -------------------------------------------------------------------------------- /main.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | "github.com/hashicorp/terraform-plugin-sdk/plugin" 5 | "github.com/hashicorp/terraform-plugin-sdk/terraform" 6 | "github.com/tpretz/terraform-provider-zabbix/provider" 7 | ) 8 | 9 | func main() { 10 | plugin.Serve(&plugin.ServeOpts{ 11 | ProviderFunc: func() terraform.ResourceProvider { 12 | return provider.Provider() 13 | }, 14 | }) 15 | } 16 | -------------------------------------------------------------------------------- /docker/.env_db_mysql: -------------------------------------------------------------------------------- 1 | # DB_SERVER_HOST=mysql-server 2 | # DB_SERVER_PORT=3306 3 | # MYSQL_USER=zabbix 4 | MYSQL_USER_FILE=/run/secrets/MYSQL_USER 5 | # MYSQL_PASSWORD=zabbix 6 | MYSQL_PASSWORD_FILE=/run/secrets/MYSQL_PASSWORD 7 | # MYSQL_ROOT_PASSWORD= 8 | MYSQL_ROOT_PASSWORD_FILE=/run/secrets/MYSQL_ROOT_PASSWORD 9 | # MYSQL_ALLOW_EMPTY_PASSWORD=false 10 | # MYSQL_DATABASE=zabbix 11 | MYSQL_DATABASE=zabbix 12 | -------------------------------------------------------------------------------- /templates/index.md.tmpl: -------------------------------------------------------------------------------- 1 | --- 2 | page_title: "zabbix Provider" 3 | subcategory: "" 4 | description: |- 5 | The Zabbix provider provides resources to interact with a Zabbix Monitoring Server. 6 | --- 7 | 8 | # zabbix Provider 9 | 10 | The Zabbix provider provides resources to interact with a Zabbix Monitoring Server. 11 | 12 | ## Example Usage 13 | 14 | {{tffile "examples/provider/provider.tf"}} 15 | 16 | {{ .SchemaMarkdown | trimspace }} 17 | -------------------------------------------------------------------------------- /examples/provider/provider.tf: -------------------------------------------------------------------------------- 1 | provider "zabbix" { 2 | # Required 3 | username = "" 4 | password = "" 5 | url = "http://example.com/api_jsonrpc.php" 6 | 7 | # Optional 8 | 9 | # Disable TLS verfication (false by default) 10 | tls_insecure = true 11 | 12 | # Serialize Zabbix API calls (false by default) 13 | # Note: race conditions have been observed, enable this if required 14 | serialize = true 15 | } 16 | 17 | -------------------------------------------------------------------------------- /docs/data-sources/proxy.md: -------------------------------------------------------------------------------- 1 | --- 2 | # generated by https://github.com/hashicorp/terraform-plugin-docs 3 | page_title: "zabbix_proxy Data Source - terraform-provider-zabbix" 4 | subcategory: "" 5 | description: |- 6 | 7 | --- 8 | 9 | # zabbix_proxy (Data Source) 10 | 11 | 12 | 13 | 14 | 15 | 16 | ## Schema 17 | 18 | ### Required 19 | 20 | - **host** (String) FQDN of proxy 21 | 22 | ### Optional 23 | 24 | - **id** (String) The ID of this resource. 25 | 26 | 27 | -------------------------------------------------------------------------------- /docs/resources/hostgroup.md: -------------------------------------------------------------------------------- 1 | --- 2 | # generated by https://github.com/hashicorp/terraform-plugin-docs 3 | page_title: "zabbix_hostgroup Resource - terraform-provider-zabbix" 4 | subcategory: "" 5 | description: |- 6 | 7 | --- 8 | 9 | # zabbix_hostgroup (Resource) 10 | 11 | 12 | 13 | 14 | 15 | 16 | ## Schema 17 | 18 | ### Required 19 | 20 | - **name** (String) Hostgroup Name 21 | 22 | ### Optional 23 | 24 | - **id** (String) The ID of this resource. 25 | 26 | 27 | -------------------------------------------------------------------------------- /docs/data-sources/hostgroup.md: -------------------------------------------------------------------------------- 1 | --- 2 | # generated by https://github.com/hashicorp/terraform-plugin-docs 3 | page_title: "zabbix_hostgroup Data Source - terraform-provider-zabbix" 4 | subcategory: "" 5 | description: |- 6 | 7 | --- 8 | 9 | # zabbix_hostgroup (Data Source) 10 | 11 | 12 | 13 | 14 | 15 | 16 | ## Schema 17 | 18 | ### Required 19 | 20 | - **name** (String) Hostgroup Name 21 | 22 | ### Optional 23 | 24 | - **id** (String) The ID of this resource. 25 | 26 | 27 | -------------------------------------------------------------------------------- /docker/.env_web: -------------------------------------------------------------------------------- 1 | # ZBX_SERVER_HOST=zabbix-server 2 | # ZBX_SERVER_PORT=10051 3 | ZBX_SERVER_NAME=Composed installation 4 | # ZBX_HISTORYSTORAGEURL=http://elasticsearch:9200/ # Available since 3.4.5 5 | # ZBX_HISTORYSTORAGETYPES=['uint', 'dbl', 'str', 'text', 'log'] # Available since 3.4.5 6 | # ZBX_MAXEXECUTIONTIME=600 7 | # ZBX_MEMORYLIMIT=128M 8 | # ZBX_POSTMAXSIZE=16M 9 | # ZBX_UPLOADMAXFILESIZE=2M 10 | # ZBX_MAXINPUTTIME=300 11 | # ZBX_SESSION_NAME=zbx_sessionid 12 | # Timezone one of: http://php.net/manual/en/timezones.php 13 | # PHP_TZ=Europe/Riga 14 | -------------------------------------------------------------------------------- /docs/resources/application.md: -------------------------------------------------------------------------------- 1 | --- 2 | # generated by https://github.com/hashicorp/terraform-plugin-docs 3 | page_title: "zabbix_application Resource - terraform-provider-zabbix" 4 | subcategory: "" 5 | description: |- 6 | 7 | --- 8 | 9 | # zabbix_application (Resource) 10 | 11 | 12 | 13 | 14 | 15 | 16 | ## Schema 17 | 18 | ### Required 19 | 20 | - **hostid** (String) Host ID 21 | - **name** (String) Application Name 22 | 23 | ### Optional 24 | 25 | - **id** (String) The ID of this resource. 26 | 27 | 28 | -------------------------------------------------------------------------------- /docs/data-sources/application.md: -------------------------------------------------------------------------------- 1 | --- 2 | # generated by https://github.com/hashicorp/terraform-plugin-docs 3 | page_title: "zabbix_application Data Source - terraform-provider-zabbix" 4 | subcategory: "" 5 | description: |- 6 | 7 | --- 8 | 9 | # zabbix_application (Data Source) 10 | 11 | 12 | 13 | 14 | 15 | 16 | ## Schema 17 | 18 | ### Required 19 | 20 | - **name** (String) Application Name 21 | 22 | ### Optional 23 | 24 | - **hostid** (String) Host ID 25 | - **id** (String) The ID of this resource. 26 | 27 | 28 | -------------------------------------------------------------------------------- /provider/log.go: -------------------------------------------------------------------------------- 1 | package provider 2 | 3 | import ( 4 | logger "log" 5 | "os" 6 | ) 7 | 8 | // this changes and no longer works if accessed later 9 | var stderr = os.Stderr 10 | 11 | type Log struct{} 12 | 13 | func (Log) Trace(msg string, args ...interface{}) { 14 | logger.Printf("[TRACE] "+msg, args...) 15 | } 16 | func (Log) Debug(msg string, args ...interface{}) { 17 | logger.Printf("[DEBUG] "+msg, args...) 18 | } 19 | func (Log) Info(msg string, args ...interface{}) { 20 | logger.Printf("[INFO] "+msg, args...) 21 | } 22 | func (Log) Warn(msg string, args ...interface{}) { 23 | logger.Printf("[WARN] "+msg, args...) 24 | } 25 | func (Log) Error(msg string, args ...interface{}) { 26 | logger.Printf("[ERROR] "+msg, args...) 27 | } 28 | 29 | var log = &Log{} 30 | -------------------------------------------------------------------------------- /docs/data-sources/template.md: -------------------------------------------------------------------------------- 1 | --- 2 | # generated by https://github.com/hashicorp/terraform-plugin-docs 3 | page_title: "zabbix_template Data Source - terraform-provider-zabbix" 4 | subcategory: "" 5 | description: |- 6 | 7 | --- 8 | 9 | # zabbix_template (Data Source) 10 | 11 | 12 | 13 | 14 | 15 | 16 | ## Schema 17 | 18 | ### Optional 19 | 20 | - **host** (String) Template hostname (internal name) 21 | - **id** (String) The ID of this resource. 22 | - **macro** (Block List) (see [below for nested schema](#nestedblock--macro)) 23 | - **name** (String) Template Display Name (defaults to host) 24 | 25 | ### Read-Only 26 | 27 | - **description** (String) Template description 28 | - **groups** (Set of String) Host Group IDs 29 | 30 | 31 | ### Nested Schema for `macro` 32 | 33 | Required: 34 | 35 | - **name** (String) Macro Name (key) 36 | - **value** (String) Macro Value 37 | 38 | Read-Only: 39 | 40 | - **id** (String) The ID of this resource. 41 | 42 | 43 | -------------------------------------------------------------------------------- /provider/provider_test.go: -------------------------------------------------------------------------------- 1 | package provider 2 | 3 | import ( 4 | "github.com/hashicorp/terraform-plugin-sdk/helper/schema" 5 | "github.com/hashicorp/terraform-plugin-sdk/terraform" 6 | "os" 7 | "testing" 8 | ) 9 | 10 | var testAccProviders map[string]terraform.ResourceProvider 11 | var testAccProvider *schema.Provider 12 | 13 | func init() { 14 | testAccProvider = Provider() 15 | testAccProviders = map[string]terraform.ResourceProvider{ 16 | "zabbix": testAccProvider, 17 | } 18 | } 19 | 20 | func TestProvider(t *testing.T) { 21 | if err := Provider().InternalValidate(); err != nil { 22 | t.Fatalf("err: %s", err) 23 | } 24 | } 25 | 26 | func TestProvider_impl(t *testing.T) { 27 | var _ terraform.ResourceProvider = Provider() 28 | } 29 | 30 | func testAccPreCheck(t *testing.T) { 31 | 32 | required := []string{"ZABBIX_URL", "ZABBIX_USER", "ZABBIX_PASS"} 33 | 34 | for _, envName := range required { 35 | if err := os.Getenv(envName); err == "" { 36 | t.Fatalf("environment variable %s must be set", envName) 37 | } 38 | } 39 | } 40 | -------------------------------------------------------------------------------- /docs/resources/template.md: -------------------------------------------------------------------------------- 1 | --- 2 | # generated by https://github.com/hashicorp/terraform-plugin-docs 3 | page_title: "zabbix_template Resource - terraform-provider-zabbix" 4 | subcategory: "" 5 | description: |- 6 | 7 | --- 8 | 9 | # zabbix_template (Resource) 10 | 11 | 12 | 13 | 14 | 15 | 16 | ## Schema 17 | 18 | ### Required 19 | 20 | - **groups** (Set of String) Host Group IDs 21 | - **host** (String) Template hostname (internal name) 22 | 23 | ### Optional 24 | 25 | - **description** (String) Template description 26 | - **id** (String) The ID of this resource. 27 | - **macro** (Block List) (see [below for nested schema](#nestedblock--macro)) 28 | - **name** (String) Template Display Name (defaults to host) 29 | - **templates** (Set of String) linked templates 30 | 31 | 32 | ### Nested Schema for `macro` 33 | 34 | Required: 35 | 36 | - **name** (String) Macro Name (key) 37 | - **value** (String) Macro Value 38 | 39 | Read-Only: 40 | 41 | - **id** (String) The ID of this resource. 42 | 43 | 44 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2020 Thomas Pressnell 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /docs/index.md: -------------------------------------------------------------------------------- 1 | --- 2 | page_title: "zabbix Provider" 3 | subcategory: "" 4 | description: |- 5 | The Zabbix provider provides resources to interact with a Zabbix Monitoring Server. 6 | --- 7 | 8 | # zabbix Provider 9 | 10 | The Zabbix provider provides resources to interact with a Zabbix Monitoring Server. 11 | 12 | ## Example Usage 13 | 14 | ```terraform 15 | provider "zabbix" { 16 | # Required 17 | username = "" 18 | password = "" 19 | url = "http://example.com/api_jsonrpc.php" 20 | 21 | # Optional 22 | 23 | # Disable TLS verfication (false by default) 24 | tls_insecure = true 25 | 26 | # Serialize Zabbix API calls (false by default) 27 | # Note: race conditions have been observed, enable this if required 28 | serialize = true 29 | } 30 | ``` 31 | 32 | 33 | ## Schema 34 | 35 | ### Required 36 | 37 | - **password** (String) Zabbix API password 38 | - **url** (String) Zabbix API url 39 | - **username** (String) Zabbix API username 40 | 41 | ### Optional 42 | 43 | - **serialize** (Boolean) Serialize API requests, if required due to API race conditions 44 | - **tls_insecure** (Boolean) Disable TLS certificate checking (for testing use only) 45 | -------------------------------------------------------------------------------- /docs/resources/trigger.md: -------------------------------------------------------------------------------- 1 | --- 2 | # generated by https://github.com/hashicorp/terraform-plugin-docs 3 | page_title: "zabbix_trigger Resource - terraform-provider-zabbix" 4 | subcategory: "" 5 | description: |- 6 | 7 | --- 8 | 9 | # zabbix_trigger (Resource) 10 | 11 | 12 | 13 | 14 | 15 | 16 | ## Schema 17 | 18 | ### Required 19 | 20 | - **expression** (String) Trigger Expression 21 | - **name** (String) Trigger name 22 | 23 | ### Optional 24 | 25 | - **comments** (String) Trigger comments 26 | - **correlation_tag** (String) correlation tag 27 | - **dependencies** (Set of String) Trigger Dependencies 28 | - **enabled** (Boolean) Enable this trigger 29 | - **id** (String) The ID of this resource. 30 | - **manual_close** (Boolean) Manual resolution 31 | - **multiple** (Boolean) generate multiple events 32 | - **priority** (String) Trigger Priority level, one of: high, disaster, not_classified, info, warn, average 33 | - **recovery_expression** (String) use recovery expression (recovery_none must not be true) 34 | - **recovery_none** (Boolean) set recovery mode to none 35 | - **tag** (Block Set) (see [below for nested schema](#nestedblock--tag)) 36 | - **url** (String) link to url relevent to trigger 37 | 38 | 39 | ### Nested Schema for `tag` 40 | 41 | Required: 42 | 43 | - **key** (String) Tag Key 44 | 45 | Optional: 46 | 47 | - **value** (String) Tag Value 48 | 49 | 50 | -------------------------------------------------------------------------------- /docs/resources/proto_trigger.md: -------------------------------------------------------------------------------- 1 | --- 2 | # generated by https://github.com/hashicorp/terraform-plugin-docs 3 | page_title: "zabbix_proto_trigger Resource - terraform-provider-zabbix" 4 | subcategory: "" 5 | description: |- 6 | 7 | --- 8 | 9 | # zabbix_proto_trigger (Resource) 10 | 11 | 12 | 13 | 14 | 15 | 16 | ## Schema 17 | 18 | ### Required 19 | 20 | - **expression** (String) Trigger Expression 21 | - **name** (String) Trigger name 22 | 23 | ### Optional 24 | 25 | - **comments** (String) Trigger comments 26 | - **correlation_tag** (String) correlation tag 27 | - **dependencies** (Set of String) Trigger Dependencies 28 | - **enabled** (Boolean) Enable this trigger 29 | - **id** (String) The ID of this resource. 30 | - **manual_close** (Boolean) Manual resolution 31 | - **multiple** (Boolean) generate multiple events 32 | - **priority** (String) Trigger Priority level, one of: high, disaster, not_classified, info, warn, average 33 | - **recovery_expression** (String) use recovery expression (recovery_none must not be true) 34 | - **recovery_none** (Boolean) set recovery mode to none 35 | - **tag** (Block Set) (see [below for nested schema](#nestedblock--tag)) 36 | - **url** (String) link to url relevent to trigger 37 | 38 | 39 | ### Nested Schema for `tag` 40 | 41 | Required: 42 | 43 | - **key** (String) Tag Key 44 | 45 | Optional: 46 | 47 | - **value** (String) Tag Value 48 | 49 | 50 | -------------------------------------------------------------------------------- /provider/resource_snmptrap_common.go: -------------------------------------------------------------------------------- 1 | package provider 2 | 3 | import ( 4 | "github.com/hashicorp/terraform-plugin-sdk/helper/schema" 5 | "github.com/tpretz/go-zabbix-api" 6 | ) 7 | 8 | // terraform resource handler for item type 9 | func resourceItemSnmpTrap() *schema.Resource { 10 | return &schema.Resource{ 11 | Create: itemGetCreateWrapper(itemSnmpTrapModFunc, itemSnmpTrapReadFunc), 12 | Read: itemGetReadWrapper(itemSnmpTrapReadFunc), 13 | Update: itemGetUpdateWrapper(itemSnmpTrapModFunc, itemSnmpTrapReadFunc), 14 | Delete: resourceItemDelete, 15 | Importer: &schema.ResourceImporter{ 16 | State: schema.ImportStatePassthrough, 17 | }, 18 | 19 | Schema: itemCommonSchema, 20 | } 21 | } 22 | func resourceProtoItemSnmpTrap() *schema.Resource { 23 | return &schema.Resource{ 24 | Create: protoItemGetCreateWrapper(itemSnmpTrapModFunc, itemSnmpTrapReadFunc), 25 | Read: protoItemGetReadWrapper(itemSnmpTrapReadFunc), 26 | Update: protoItemGetUpdateWrapper(itemSnmpTrapModFunc, itemSnmpTrapReadFunc), 27 | Delete: resourceProtoItemDelete, 28 | Importer: &schema.ResourceImporter{ 29 | State: schema.ImportStatePassthrough, 30 | }, 31 | 32 | Schema: mergeSchemas(itemCommonSchema, itemPrototypeSchema), 33 | } 34 | } 35 | 36 | // Custom mod handler for item type 37 | func itemSnmpTrapModFunc(d *schema.ResourceData, m interface{}, item *zabbix.Item) { 38 | item.Type = zabbix.SNMPTrap 39 | } 40 | 41 | // Custom read handler for item type 42 | func itemSnmpTrapReadFunc(d *schema.ResourceData, m interface{}, item *zabbix.Item) { 43 | } 44 | -------------------------------------------------------------------------------- /docker/.env_srv: -------------------------------------------------------------------------------- 1 | # ZBX_LISTENIP= 2 | # ZBX_HISTORYSTORAGEURL=http://elasticsearch:9200/ # Available since 3.4.5 3 | # ZBX_HISTORYSTORAGETYPES=uint,dbl,str,log,text # Available since 3.4.5 4 | # ZBX_DEBUGLEVEL=3 5 | # ZBX_STARTPOLLERS=5 6 | # ZBX_IPMIPOLLERS=0 7 | # ZBX_STARTPREPROCESSORS=3 # Available since 3.4.0 8 | # ZBX_STARTPOLLERSUNREACHABLE=1 9 | # ZBX_STARTTRAPPERS=5 10 | # ZBX_STARTPINGERS=1 11 | # ZBX_STARTDISCOVERERS=1 12 | # ZBX_STARTHTTPPOLLERS=1 13 | # ZBX_STARTTIMERS=1 14 | # ZBX_STARTESCALATORS=1 15 | # ZBX_STARTALERTERS=3 # Available since 3.4.0 16 | ZBX_JAVAGATEWAY_ENABLE=true 17 | # ZBX_JAVAGATEWAY=zabbix-java-gateway 18 | # ZBX_JAVAGATEWAYPORT=10052 19 | ZBX_STARTJAVAPOLLERS=5 20 | # ZBX_STARTVMWARECOLLECTORS=0 21 | # ZBX_VMWAREFREQUENCY=60 22 | # ZBX_VMWAREPERFFREQUENCY=60 23 | # ZBX_VMWARECACHESIZE=8M 24 | # ZBX_VMWARETIMEOUT=10 25 | ZBX_ENABLE_SNMP_TRAPS=true 26 | # ZBX_SOURCEIP= 27 | # ZBX_HOUSEKEEPINGFREQUENCY=1 28 | # ZBX_MAXHOUSEKEEPERDELETE=5000 29 | # ZBX_SENDERFREQUENCY=30 30 | # ZBX_CACHESIZE=8M 31 | # ZBX_CACHEUPDATEFREQUENCY=60 32 | # ZBX_STARTDBSYNCERS=4 33 | # ZBX_HISTORYCACHESIZE=16M 34 | # ZBX_HISTORYINDEXCACHESIZE=4M 35 | # ZBX_TRENDCACHESIZE=4M 36 | # ZBX_VALUECACHESIZE=8M 37 | # ZBX_TIMEOUT=4 38 | # ZBX_TRAPPERIMEOUT=300 39 | # ZBX_UNREACHABLEPERIOD=45 40 | # ZBX_UNAVAILABLEDELAY=60 41 | # ZBX_UNREACHABLEDELAY=15 42 | # ZBX_LOGSLOWQUERIES=3000 43 | # ZBX_STARTPROXYPOLLERS=1 44 | # ZBX_PROXYCONFIGFREQUENCY=3600 45 | # ZBX_PROXYDATAFREQUENCY=1 46 | # ZBX_LOADMODULE="dummy1.so,dummy2.so,dummy10.so" 47 | # ZBX_TLSCAFILE= 48 | # ZBX_TLSCRLFILE= 49 | # ZBX_TLSCERTFILE= 50 | # ZBX_TLSKEYFILE= 51 | -------------------------------------------------------------------------------- /docs/resources/item_snmptrap.md: -------------------------------------------------------------------------------- 1 | --- 2 | # generated by https://github.com/hashicorp/terraform-plugin-docs 3 | page_title: "zabbix_item_snmptrap Resource - terraform-provider-zabbix" 4 | subcategory: "" 5 | description: |- 6 | 7 | --- 8 | 9 | # zabbix_item_snmptrap (Resource) 10 | 11 | 12 | 13 | 14 | 15 | 16 | ## Schema 17 | 18 | ### Required 19 | 20 | - **hostid** (String) Host ID 21 | - **key** (String) Item KEY 22 | - **name** (String) Item Name 23 | - **valuetype** (String) Item Value Type, one of: float, character, log, unsigned, text 24 | 25 | ### Optional 26 | 27 | - **applications** (Set of String) Application IDs to associate this item with 28 | - **history** (String) Item History 29 | - **id** (String) The ID of this resource. 30 | - **preprocessor** (Block List) (see [below for nested schema](#nestedblock--preprocessor)) 31 | - **tag** (Block Set) (see [below for nested schema](#nestedblock--tag)) 32 | - **trends** (String) Item Trends 33 | 34 | 35 | ### Nested Schema for `preprocessor` 36 | 37 | Required: 38 | 39 | - **type** (String) Preprocessor type, zabbix identifier number 40 | 41 | Optional: 42 | 43 | - **error_handler** (String) 44 | - **error_handler_params** (String) 45 | - **params** (List of String) Preprocessor parameters 46 | 47 | Read-Only: 48 | 49 | - **id** (String) The ID of this resource. 50 | 51 | 52 | 53 | ### Nested Schema for `tag` 54 | 55 | Required: 56 | 57 | - **key** (String) Tag Key 58 | 59 | Optional: 60 | 61 | - **value** (String) Tag Value 62 | 63 | 64 | -------------------------------------------------------------------------------- /docs/resources/item_trapper.md: -------------------------------------------------------------------------------- 1 | --- 2 | # generated by https://github.com/hashicorp/terraform-plugin-docs 3 | page_title: "zabbix_item_trapper Resource - terraform-provider-zabbix" 4 | subcategory: "" 5 | description: |- 6 | 7 | --- 8 | 9 | # zabbix_item_trapper (Resource) 10 | 11 | 12 | 13 | 14 | 15 | 16 | ## Schema 17 | 18 | ### Required 19 | 20 | - **hostid** (String) Host ID 21 | - **key** (String) Item KEY 22 | - **name** (String) Item Name 23 | - **valuetype** (String) Item Value Type, one of: float, character, log, unsigned, text 24 | 25 | ### Optional 26 | 27 | - **applications** (Set of String) Application IDs to associate this item with 28 | - **history** (String) Item History 29 | - **id** (String) The ID of this resource. 30 | - **preprocessor** (Block List) (see [below for nested schema](#nestedblock--preprocessor)) 31 | - **tag** (Block Set) (see [below for nested schema](#nestedblock--tag)) 32 | - **trends** (String) Item Trends 33 | 34 | 35 | ### Nested Schema for `preprocessor` 36 | 37 | Required: 38 | 39 | - **type** (String) Preprocessor type, zabbix identifier number 40 | 41 | Optional: 42 | 43 | - **error_handler** (String) 44 | - **error_handler_params** (String) 45 | - **params** (List of String) Preprocessor parameters 46 | 47 | Read-Only: 48 | 49 | - **id** (String) The ID of this resource. 50 | 51 | 52 | 53 | ### Nested Schema for `tag` 54 | 55 | Required: 56 | 57 | - **key** (String) Tag Key 58 | 59 | Optional: 60 | 61 | - **value** (String) Tag Value 62 | 63 | 64 | -------------------------------------------------------------------------------- /docs/resources/item_aggregate.md: -------------------------------------------------------------------------------- 1 | --- 2 | # generated by https://github.com/hashicorp/terraform-plugin-docs 3 | page_title: "zabbix_item_aggregate Resource - terraform-provider-zabbix" 4 | subcategory: "" 5 | description: |- 6 | 7 | --- 8 | 9 | # zabbix_item_aggregate (Resource) 10 | 11 | 12 | 13 | 14 | 15 | 16 | ## Schema 17 | 18 | ### Required 19 | 20 | - **hostid** (String) Host ID 21 | - **key** (String) Item KEY 22 | - **name** (String) Item Name 23 | - **valuetype** (String) Item Value Type, one of: float, character, log, unsigned, text 24 | 25 | ### Optional 26 | 27 | - **applications** (Set of String) Application IDs to associate this item with 28 | - **delay** (String) Item Delay period 29 | - **history** (String) Item History 30 | - **id** (String) The ID of this resource. 31 | - **preprocessor** (Block List) (see [below for nested schema](#nestedblock--preprocessor)) 32 | - **tag** (Block Set) (see [below for nested schema](#nestedblock--tag)) 33 | - **trends** (String) Item Trends 34 | 35 | 36 | ### Nested Schema for `preprocessor` 37 | 38 | Required: 39 | 40 | - **type** (String) Preprocessor type, zabbix identifier number 41 | 42 | Optional: 43 | 44 | - **error_handler** (String) 45 | - **error_handler_params** (String) 46 | - **params** (List of String) Preprocessor parameters 47 | 48 | Read-Only: 49 | 50 | - **id** (String) The ID of this resource. 51 | 52 | 53 | 54 | ### Nested Schema for `tag` 55 | 56 | Required: 57 | 58 | - **key** (String) Tag Key 59 | 60 | Optional: 61 | 62 | - **value** (String) Tag Value 63 | 64 | 65 | -------------------------------------------------------------------------------- /docs/resources/item_dependent.md: -------------------------------------------------------------------------------- 1 | --- 2 | # generated by https://github.com/hashicorp/terraform-plugin-docs 3 | page_title: "zabbix_item_dependent Resource - terraform-provider-zabbix" 4 | subcategory: "" 5 | description: |- 6 | 7 | --- 8 | 9 | # zabbix_item_dependent (Resource) 10 | 11 | 12 | 13 | 14 | 15 | 16 | ## Schema 17 | 18 | ### Required 19 | 20 | - **hostid** (String) Host ID 21 | - **key** (String) Item KEY 22 | - **master_itemid** (String) Master Item ID 23 | - **name** (String) Item Name 24 | - **valuetype** (String) Item Value Type, one of: float, character, log, unsigned, text 25 | 26 | ### Optional 27 | 28 | - **applications** (Set of String) Application IDs to associate this item with 29 | - **history** (String) Item History 30 | - **id** (String) The ID of this resource. 31 | - **preprocessor** (Block List) (see [below for nested schema](#nestedblock--preprocessor)) 32 | - **tag** (Block Set) (see [below for nested schema](#nestedblock--tag)) 33 | - **trends** (String) Item Trends 34 | 35 | 36 | ### Nested Schema for `preprocessor` 37 | 38 | Required: 39 | 40 | - **type** (String) Preprocessor type, zabbix identifier number 41 | 42 | Optional: 43 | 44 | - **error_handler** (String) 45 | - **error_handler_params** (String) 46 | - **params** (List of String) Preprocessor parameters 47 | 48 | Read-Only: 49 | 50 | - **id** (String) The ID of this resource. 51 | 52 | 53 | 54 | ### Nested Schema for `tag` 55 | 56 | Required: 57 | 58 | - **key** (String) Tag Key 59 | 60 | Optional: 61 | 62 | - **value** (String) Tag Value 63 | 64 | 65 | -------------------------------------------------------------------------------- /docs/resources/proto_item_trapper.md: -------------------------------------------------------------------------------- 1 | --- 2 | # generated by https://github.com/hashicorp/terraform-plugin-docs 3 | page_title: "zabbix_proto_item_trapper Resource - terraform-provider-zabbix" 4 | subcategory: "" 5 | description: |- 6 | 7 | --- 8 | 9 | # zabbix_proto_item_trapper (Resource) 10 | 11 | 12 | 13 | 14 | 15 | 16 | ## Schema 17 | 18 | ### Required 19 | 20 | - **hostid** (String) Host ID 21 | - **key** (String) Item KEY 22 | - **name** (String) Item Name 23 | - **ruleid** (String) LLD Rule ID 24 | - **valuetype** (String) Item Value Type, one of: float, character, log, unsigned, text 25 | 26 | ### Optional 27 | 28 | - **applications** (Set of String) Application IDs to associate this item with 29 | - **history** (String) Item History 30 | - **id** (String) The ID of this resource. 31 | - **preprocessor** (Block List) (see [below for nested schema](#nestedblock--preprocessor)) 32 | - **tag** (Block Set) (see [below for nested schema](#nestedblock--tag)) 33 | - **trends** (String) Item Trends 34 | 35 | 36 | ### Nested Schema for `preprocessor` 37 | 38 | Required: 39 | 40 | - **type** (String) Preprocessor type, zabbix identifier number 41 | 42 | Optional: 43 | 44 | - **error_handler** (String) 45 | - **error_handler_params** (String) 46 | - **params** (List of String) Preprocessor parameters 47 | 48 | Read-Only: 49 | 50 | - **id** (String) The ID of this resource. 51 | 52 | 53 | 54 | ### Nested Schema for `tag` 55 | 56 | Required: 57 | 58 | - **key** (String) Tag Key 59 | 60 | Optional: 61 | 62 | - **value** (String) Tag Value 63 | 64 | 65 | -------------------------------------------------------------------------------- /docs/resources/proto_item_snmptrap.md: -------------------------------------------------------------------------------- 1 | --- 2 | # generated by https://github.com/hashicorp/terraform-plugin-docs 3 | page_title: "zabbix_proto_item_snmptrap Resource - terraform-provider-zabbix" 4 | subcategory: "" 5 | description: |- 6 | 7 | --- 8 | 9 | # zabbix_proto_item_snmptrap (Resource) 10 | 11 | 12 | 13 | 14 | 15 | 16 | ## Schema 17 | 18 | ### Required 19 | 20 | - **hostid** (String) Host ID 21 | - **key** (String) Item KEY 22 | - **name** (String) Item Name 23 | - **ruleid** (String) LLD Rule ID 24 | - **valuetype** (String) Item Value Type, one of: float, character, log, unsigned, text 25 | 26 | ### Optional 27 | 28 | - **applications** (Set of String) Application IDs to associate this item with 29 | - **history** (String) Item History 30 | - **id** (String) The ID of this resource. 31 | - **preprocessor** (Block List) (see [below for nested schema](#nestedblock--preprocessor)) 32 | - **tag** (Block Set) (see [below for nested schema](#nestedblock--tag)) 33 | - **trends** (String) Item Trends 34 | 35 | 36 | ### Nested Schema for `preprocessor` 37 | 38 | Required: 39 | 40 | - **type** (String) Preprocessor type, zabbix identifier number 41 | 42 | Optional: 43 | 44 | - **error_handler** (String) 45 | - **error_handler_params** (String) 46 | - **params** (List of String) Preprocessor parameters 47 | 48 | Read-Only: 49 | 50 | - **id** (String) The ID of this resource. 51 | 52 | 53 | 54 | ### Nested Schema for `tag` 55 | 56 | Required: 57 | 58 | - **key** (String) Tag Key 59 | 60 | Optional: 61 | 62 | - **value** (String) Tag Value 63 | 64 | 65 | -------------------------------------------------------------------------------- /docs/resources/item_calculated.md: -------------------------------------------------------------------------------- 1 | --- 2 | # generated by https://github.com/hashicorp/terraform-plugin-docs 3 | page_title: "zabbix_item_calculated Resource - terraform-provider-zabbix" 4 | subcategory: "" 5 | description: |- 6 | 7 | --- 8 | 9 | # zabbix_item_calculated (Resource) 10 | 11 | 12 | 13 | 14 | 15 | 16 | ## Schema 17 | 18 | ### Required 19 | 20 | - **formula** (String) Formula 21 | - **hostid** (String) Host ID 22 | - **key** (String) Item KEY 23 | - **name** (String) Item Name 24 | - **valuetype** (String) Item Value Type, one of: float, character, log, unsigned, text 25 | 26 | ### Optional 27 | 28 | - **applications** (Set of String) Application IDs to associate this item with 29 | - **delay** (String) Item Delay period 30 | - **history** (String) Item History 31 | - **id** (String) The ID of this resource. 32 | - **preprocessor** (Block List) (see [below for nested schema](#nestedblock--preprocessor)) 33 | - **tag** (Block Set) (see [below for nested schema](#nestedblock--tag)) 34 | - **trends** (String) Item Trends 35 | 36 | 37 | ### Nested Schema for `preprocessor` 38 | 39 | Required: 40 | 41 | - **type** (String) Preprocessor type, zabbix identifier number 42 | 43 | Optional: 44 | 45 | - **error_handler** (String) 46 | - **error_handler_params** (String) 47 | - **params** (List of String) Preprocessor parameters 48 | 49 | Read-Only: 50 | 51 | - **id** (String) The ID of this resource. 52 | 53 | 54 | 55 | ### Nested Schema for `tag` 56 | 57 | Required: 58 | 59 | - **key** (String) Tag Key 60 | 61 | Optional: 62 | 63 | - **value** (String) Tag Value 64 | 65 | 66 | -------------------------------------------------------------------------------- /provider/resource_aggregate_common.go: -------------------------------------------------------------------------------- 1 | package provider 2 | 3 | import ( 4 | "github.com/hashicorp/terraform-plugin-sdk/helper/schema" 5 | "github.com/tpretz/go-zabbix-api" 6 | ) 7 | 8 | // terraform resource handler for item type 9 | func resourceItemAggregate() *schema.Resource { 10 | return &schema.Resource{ 11 | Create: itemGetCreateWrapper(itemAggregateModFunc, itemAggregateReadFunc), 12 | Read: itemGetReadWrapper(itemAggregateReadFunc), 13 | Update: itemGetUpdateWrapper(itemAggregateModFunc, itemAggregateReadFunc), 14 | Delete: resourceItemDelete, 15 | Importer: &schema.ResourceImporter{ 16 | State: schema.ImportStatePassthrough, 17 | }, 18 | 19 | Schema: mergeSchemas(itemCommonSchema, itemDelaySchema), 20 | } 21 | } 22 | func resourceProtoItemAggregate() *schema.Resource { 23 | return &schema.Resource{ 24 | Create: protoItemGetCreateWrapper(itemAggregateModFunc, itemAggregateReadFunc), 25 | Read: protoItemGetReadWrapper(itemAggregateReadFunc), 26 | Update: protoItemGetUpdateWrapper(itemAggregateModFunc, itemAggregateReadFunc), 27 | Delete: resourceProtoItemDelete, 28 | Importer: &schema.ResourceImporter{ 29 | State: schema.ImportStatePassthrough, 30 | }, 31 | 32 | Schema: mergeSchemas(itemCommonSchema, itemDelaySchema, itemPrototypeSchema), 33 | } 34 | } 35 | 36 | // Custom mod handler for item type 37 | func itemAggregateModFunc(d *schema.ResourceData, m interface{}, item *zabbix.Item) { 38 | item.Type = zabbix.ZabbixAggregate 39 | item.Delay = d.Get("delay").(string) 40 | } 41 | 42 | // Custom read handler for item type 43 | func itemAggregateReadFunc(d *schema.ResourceData, m interface{}, item *zabbix.Item) { 44 | d.Set("delay", item.Delay) 45 | } 46 | -------------------------------------------------------------------------------- /docs/resources/item_simple.md: -------------------------------------------------------------------------------- 1 | --- 2 | # generated by https://github.com/hashicorp/terraform-plugin-docs 3 | page_title: "zabbix_item_simple Resource - terraform-provider-zabbix" 4 | subcategory: "" 5 | description: |- 6 | 7 | --- 8 | 9 | # zabbix_item_simple (Resource) 10 | 11 | 12 | 13 | 14 | 15 | 16 | ## Schema 17 | 18 | ### Required 19 | 20 | - **hostid** (String) Host ID 21 | - **key** (String) Item KEY 22 | - **name** (String) Item Name 23 | - **valuetype** (String) Item Value Type, one of: float, character, log, unsigned, text 24 | 25 | ### Optional 26 | 27 | - **applications** (Set of String) Application IDs to associate this item with 28 | - **delay** (String) Item Delay period 29 | - **history** (String) Item History 30 | - **id** (String) The ID of this resource. 31 | - **interfaceid** (String) Host Interface ID 32 | - **preprocessor** (Block List) (see [below for nested schema](#nestedblock--preprocessor)) 33 | - **tag** (Block Set) (see [below for nested schema](#nestedblock--tag)) 34 | - **trends** (String) Item Trends 35 | 36 | 37 | ### Nested Schema for `preprocessor` 38 | 39 | Required: 40 | 41 | - **type** (String) Preprocessor type, zabbix identifier number 42 | 43 | Optional: 44 | 45 | - **error_handler** (String) 46 | - **error_handler_params** (String) 47 | - **params** (List of String) Preprocessor parameters 48 | 49 | Read-Only: 50 | 51 | - **id** (String) The ID of this resource. 52 | 53 | 54 | 55 | ### Nested Schema for `tag` 56 | 57 | Required: 58 | 59 | - **key** (String) Tag Key 60 | 61 | Optional: 62 | 63 | - **value** (String) Tag Value 64 | 65 | 66 | -------------------------------------------------------------------------------- /docs/resources/item_external.md: -------------------------------------------------------------------------------- 1 | --- 2 | # generated by https://github.com/hashicorp/terraform-plugin-docs 3 | page_title: "zabbix_item_external Resource - terraform-provider-zabbix" 4 | subcategory: "" 5 | description: |- 6 | 7 | --- 8 | 9 | # zabbix_item_external (Resource) 10 | 11 | 12 | 13 | 14 | 15 | 16 | ## Schema 17 | 18 | ### Required 19 | 20 | - **hostid** (String) Host ID 21 | - **key** (String) Item KEY 22 | - **name** (String) Item Name 23 | - **valuetype** (String) Item Value Type, one of: float, character, log, unsigned, text 24 | 25 | ### Optional 26 | 27 | - **applications** (Set of String) Application IDs to associate this item with 28 | - **delay** (String) Item Delay period 29 | - **history** (String) Item History 30 | - **id** (String) The ID of this resource. 31 | - **interfaceid** (String) Host Interface ID 32 | - **preprocessor** (Block List) (see [below for nested schema](#nestedblock--preprocessor)) 33 | - **tag** (Block Set) (see [below for nested schema](#nestedblock--tag)) 34 | - **trends** (String) Item Trends 35 | 36 | 37 | ### Nested Schema for `preprocessor` 38 | 39 | Required: 40 | 41 | - **type** (String) Preprocessor type, zabbix identifier number 42 | 43 | Optional: 44 | 45 | - **error_handler** (String) 46 | - **error_handler_params** (String) 47 | - **params** (List of String) Preprocessor parameters 48 | 49 | Read-Only: 50 | 51 | - **id** (String) The ID of this resource. 52 | 53 | 54 | 55 | ### Nested Schema for `tag` 56 | 57 | Required: 58 | 59 | - **key** (String) Tag Key 60 | 61 | Optional: 62 | 63 | - **value** (String) Tag Value 64 | 65 | 66 | -------------------------------------------------------------------------------- /docs/resources/item_internal.md: -------------------------------------------------------------------------------- 1 | --- 2 | # generated by https://github.com/hashicorp/terraform-plugin-docs 3 | page_title: "zabbix_item_internal Resource - terraform-provider-zabbix" 4 | subcategory: "" 5 | description: |- 6 | 7 | --- 8 | 9 | # zabbix_item_internal (Resource) 10 | 11 | 12 | 13 | 14 | 15 | 16 | ## Schema 17 | 18 | ### Required 19 | 20 | - **hostid** (String) Host ID 21 | - **key** (String) Item KEY 22 | - **name** (String) Item Name 23 | - **valuetype** (String) Item Value Type, one of: float, character, log, unsigned, text 24 | 25 | ### Optional 26 | 27 | - **applications** (Set of String) Application IDs to associate this item with 28 | - **delay** (String) Item Delay period 29 | - **history** (String) Item History 30 | - **id** (String) The ID of this resource. 31 | - **interfaceid** (String) Host Interface ID 32 | - **preprocessor** (Block List) (see [below for nested schema](#nestedblock--preprocessor)) 33 | - **tag** (Block Set) (see [below for nested schema](#nestedblock--tag)) 34 | - **trends** (String) Item Trends 35 | 36 | 37 | ### Nested Schema for `preprocessor` 38 | 39 | Required: 40 | 41 | - **type** (String) Preprocessor type, zabbix identifier number 42 | 43 | Optional: 44 | 45 | - **error_handler** (String) 46 | - **error_handler_params** (String) 47 | - **params** (List of String) Preprocessor parameters 48 | 49 | Read-Only: 50 | 51 | - **id** (String) The ID of this resource. 52 | 53 | 54 | 55 | ### Nested Schema for `tag` 56 | 57 | Required: 58 | 59 | - **key** (String) Tag Key 60 | 61 | Optional: 62 | 63 | - **value** (String) Tag Value 64 | 65 | 66 | -------------------------------------------------------------------------------- /docs/resources/proto_item_aggregate.md: -------------------------------------------------------------------------------- 1 | --- 2 | # generated by https://github.com/hashicorp/terraform-plugin-docs 3 | page_title: "zabbix_proto_item_aggregate Resource - terraform-provider-zabbix" 4 | subcategory: "" 5 | description: |- 6 | 7 | --- 8 | 9 | # zabbix_proto_item_aggregate (Resource) 10 | 11 | 12 | 13 | 14 | 15 | 16 | ## Schema 17 | 18 | ### Required 19 | 20 | - **hostid** (String) Host ID 21 | - **key** (String) Item KEY 22 | - **name** (String) Item Name 23 | - **ruleid** (String) LLD Rule ID 24 | - **valuetype** (String) Item Value Type, one of: float, character, log, unsigned, text 25 | 26 | ### Optional 27 | 28 | - **applications** (Set of String) Application IDs to associate this item with 29 | - **delay** (String) Item Delay period 30 | - **history** (String) Item History 31 | - **id** (String) The ID of this resource. 32 | - **preprocessor** (Block List) (see [below for nested schema](#nestedblock--preprocessor)) 33 | - **tag** (Block Set) (see [below for nested schema](#nestedblock--tag)) 34 | - **trends** (String) Item Trends 35 | 36 | 37 | ### Nested Schema for `preprocessor` 38 | 39 | Required: 40 | 41 | - **type** (String) Preprocessor type, zabbix identifier number 42 | 43 | Optional: 44 | 45 | - **error_handler** (String) 46 | - **error_handler_params** (String) 47 | - **params** (List of String) Preprocessor parameters 48 | 49 | Read-Only: 50 | 51 | - **id** (String) The ID of this resource. 52 | 53 | 54 | 55 | ### Nested Schema for `tag` 56 | 57 | Required: 58 | 59 | - **key** (String) Tag Key 60 | 61 | Optional: 62 | 63 | - **value** (String) Tag Value 64 | 65 | 66 | -------------------------------------------------------------------------------- /docs/resources/proto_item_dependent.md: -------------------------------------------------------------------------------- 1 | --- 2 | # generated by https://github.com/hashicorp/terraform-plugin-docs 3 | page_title: "zabbix_proto_item_dependent Resource - terraform-provider-zabbix" 4 | subcategory: "" 5 | description: |- 6 | 7 | --- 8 | 9 | # zabbix_proto_item_dependent (Resource) 10 | 11 | 12 | 13 | 14 | 15 | 16 | ## Schema 17 | 18 | ### Required 19 | 20 | - **hostid** (String) Host ID 21 | - **key** (String) Item KEY 22 | - **master_itemid** (String) Master Item ID 23 | - **name** (String) Item Name 24 | - **ruleid** (String) LLD Rule ID 25 | - **valuetype** (String) Item Value Type, one of: float, character, log, unsigned, text 26 | 27 | ### Optional 28 | 29 | - **applications** (Set of String) Application IDs to associate this item with 30 | - **history** (String) Item History 31 | - **id** (String) The ID of this resource. 32 | - **preprocessor** (Block List) (see [below for nested schema](#nestedblock--preprocessor)) 33 | - **tag** (Block Set) (see [below for nested schema](#nestedblock--tag)) 34 | - **trends** (String) Item Trends 35 | 36 | 37 | ### Nested Schema for `preprocessor` 38 | 39 | Required: 40 | 41 | - **type** (String) Preprocessor type, zabbix identifier number 42 | 43 | Optional: 44 | 45 | - **error_handler** (String) 46 | - **error_handler_params** (String) 47 | - **params** (List of String) Preprocessor parameters 48 | 49 | Read-Only: 50 | 51 | - **id** (String) The ID of this resource. 52 | 53 | 54 | 55 | ### Nested Schema for `tag` 56 | 57 | Required: 58 | 59 | - **key** (String) Tag Key 60 | 61 | Optional: 62 | 63 | - **value** (String) Tag Value 64 | 65 | 66 | -------------------------------------------------------------------------------- /docs/resources/item_agent.md: -------------------------------------------------------------------------------- 1 | --- 2 | # generated by https://github.com/hashicorp/terraform-plugin-docs 3 | page_title: "zabbix_item_agent Resource - terraform-provider-zabbix" 4 | subcategory: "" 5 | description: |- 6 | 7 | --- 8 | 9 | # zabbix_item_agent (Resource) 10 | 11 | 12 | 13 | 14 | 15 | 16 | ## Schema 17 | 18 | ### Required 19 | 20 | - **hostid** (String) Host ID 21 | - **key** (String) Item KEY 22 | - **name** (String) Item Name 23 | - **valuetype** (String) Item Value Type, one of: float, character, log, unsigned, text 24 | 25 | ### Optional 26 | 27 | - **active** (Boolean) Active zabbix agent Item 28 | - **applications** (Set of String) Application IDs to associate this item with 29 | - **delay** (String) Item Delay period 30 | - **history** (String) Item History 31 | - **id** (String) The ID of this resource. 32 | - **interfaceid** (String) Host Interface ID 33 | - **preprocessor** (Block List) (see [below for nested schema](#nestedblock--preprocessor)) 34 | - **tag** (Block Set) (see [below for nested schema](#nestedblock--tag)) 35 | - **trends** (String) Item Trends 36 | 37 | 38 | ### Nested Schema for `preprocessor` 39 | 40 | Required: 41 | 42 | - **type** (String) Preprocessor type, zabbix identifier number 43 | 44 | Optional: 45 | 46 | - **error_handler** (String) 47 | - **error_handler_params** (String) 48 | - **params** (List of String) Preprocessor parameters 49 | 50 | Read-Only: 51 | 52 | - **id** (String) The ID of this resource. 53 | 54 | 55 | 56 | ### Nested Schema for `tag` 57 | 58 | Required: 59 | 60 | - **key** (String) Tag Key 61 | 62 | Optional: 63 | 64 | - **value** (String) Tag Value 65 | 66 | 67 | -------------------------------------------------------------------------------- /docs/resources/proto_item_calculated.md: -------------------------------------------------------------------------------- 1 | --- 2 | # generated by https://github.com/hashicorp/terraform-plugin-docs 3 | page_title: "zabbix_proto_item_calculated Resource - terraform-provider-zabbix" 4 | subcategory: "" 5 | description: |- 6 | 7 | --- 8 | 9 | # zabbix_proto_item_calculated (Resource) 10 | 11 | 12 | 13 | 14 | 15 | 16 | ## Schema 17 | 18 | ### Required 19 | 20 | - **formula** (String) Formula 21 | - **hostid** (String) Host ID 22 | - **key** (String) Item KEY 23 | - **name** (String) Item Name 24 | - **ruleid** (String) LLD Rule ID 25 | - **valuetype** (String) Item Value Type, one of: float, character, log, unsigned, text 26 | 27 | ### Optional 28 | 29 | - **applications** (Set of String) Application IDs to associate this item with 30 | - **delay** (String) Item Delay period 31 | - **history** (String) Item History 32 | - **id** (String) The ID of this resource. 33 | - **preprocessor** (Block List) (see [below for nested schema](#nestedblock--preprocessor)) 34 | - **tag** (Block Set) (see [below for nested schema](#nestedblock--tag)) 35 | - **trends** (String) Item Trends 36 | 37 | 38 | ### Nested Schema for `preprocessor` 39 | 40 | Required: 41 | 42 | - **type** (String) Preprocessor type, zabbix identifier number 43 | 44 | Optional: 45 | 46 | - **error_handler** (String) 47 | - **error_handler_params** (String) 48 | - **params** (List of String) Preprocessor parameters 49 | 50 | Read-Only: 51 | 52 | - **id** (String) The ID of this resource. 53 | 54 | 55 | 56 | ### Nested Schema for `tag` 57 | 58 | Required: 59 | 60 | - **key** (String) Tag Key 61 | 62 | Optional: 63 | 64 | - **value** (String) Tag Value 65 | 66 | 67 | -------------------------------------------------------------------------------- /docs/resources/proto_item_simple.md: -------------------------------------------------------------------------------- 1 | --- 2 | # generated by https://github.com/hashicorp/terraform-plugin-docs 3 | page_title: "zabbix_proto_item_simple Resource - terraform-provider-zabbix" 4 | subcategory: "" 5 | description: |- 6 | 7 | --- 8 | 9 | # zabbix_proto_item_simple (Resource) 10 | 11 | 12 | 13 | 14 | 15 | 16 | ## Schema 17 | 18 | ### Required 19 | 20 | - **hostid** (String) Host ID 21 | - **key** (String) Item KEY 22 | - **name** (String) Item Name 23 | - **ruleid** (String) LLD Rule ID 24 | - **valuetype** (String) Item Value Type, one of: float, character, log, unsigned, text 25 | 26 | ### Optional 27 | 28 | - **applications** (Set of String) Application IDs to associate this item with 29 | - **delay** (String) Item Delay period 30 | - **history** (String) Item History 31 | - **id** (String) The ID of this resource. 32 | - **interfaceid** (String) Host Interface ID 33 | - **preprocessor** (Block List) (see [below for nested schema](#nestedblock--preprocessor)) 34 | - **tag** (Block Set) (see [below for nested schema](#nestedblock--tag)) 35 | - **trends** (String) Item Trends 36 | 37 | 38 | ### Nested Schema for `preprocessor` 39 | 40 | Required: 41 | 42 | - **type** (String) Preprocessor type, zabbix identifier number 43 | 44 | Optional: 45 | 46 | - **error_handler** (String) 47 | - **error_handler_params** (String) 48 | - **params** (List of String) Preprocessor parameters 49 | 50 | Read-Only: 51 | 52 | - **id** (String) The ID of this resource. 53 | 54 | 55 | 56 | ### Nested Schema for `tag` 57 | 58 | Required: 59 | 60 | - **key** (String) Tag Key 61 | 62 | Optional: 63 | 64 | - **value** (String) Tag Value 65 | 66 | 67 | -------------------------------------------------------------------------------- /docs/resources/proto_item_external.md: -------------------------------------------------------------------------------- 1 | --- 2 | # generated by https://github.com/hashicorp/terraform-plugin-docs 3 | page_title: "zabbix_proto_item_external Resource - terraform-provider-zabbix" 4 | subcategory: "" 5 | description: |- 6 | 7 | --- 8 | 9 | # zabbix_proto_item_external (Resource) 10 | 11 | 12 | 13 | 14 | 15 | 16 | ## Schema 17 | 18 | ### Required 19 | 20 | - **hostid** (String) Host ID 21 | - **key** (String) Item KEY 22 | - **name** (String) Item Name 23 | - **ruleid** (String) LLD Rule ID 24 | - **valuetype** (String) Item Value Type, one of: float, character, log, unsigned, text 25 | 26 | ### Optional 27 | 28 | - **applications** (Set of String) Application IDs to associate this item with 29 | - **delay** (String) Item Delay period 30 | - **history** (String) Item History 31 | - **id** (String) The ID of this resource. 32 | - **interfaceid** (String) Host Interface ID 33 | - **preprocessor** (Block List) (see [below for nested schema](#nestedblock--preprocessor)) 34 | - **tag** (Block Set) (see [below for nested schema](#nestedblock--tag)) 35 | - **trends** (String) Item Trends 36 | 37 | 38 | ### Nested Schema for `preprocessor` 39 | 40 | Required: 41 | 42 | - **type** (String) Preprocessor type, zabbix identifier number 43 | 44 | Optional: 45 | 46 | - **error_handler** (String) 47 | - **error_handler_params** (String) 48 | - **params** (List of String) Preprocessor parameters 49 | 50 | Read-Only: 51 | 52 | - **id** (String) The ID of this resource. 53 | 54 | 55 | 56 | ### Nested Schema for `tag` 57 | 58 | Required: 59 | 60 | - **key** (String) Tag Key 61 | 62 | Optional: 63 | 64 | - **value** (String) Tag Value 65 | 66 | 67 | -------------------------------------------------------------------------------- /docs/resources/proto_item_internal.md: -------------------------------------------------------------------------------- 1 | --- 2 | # generated by https://github.com/hashicorp/terraform-plugin-docs 3 | page_title: "zabbix_proto_item_internal Resource - terraform-provider-zabbix" 4 | subcategory: "" 5 | description: |- 6 | 7 | --- 8 | 9 | # zabbix_proto_item_internal (Resource) 10 | 11 | 12 | 13 | 14 | 15 | 16 | ## Schema 17 | 18 | ### Required 19 | 20 | - **hostid** (String) Host ID 21 | - **key** (String) Item KEY 22 | - **name** (String) Item Name 23 | - **ruleid** (String) LLD Rule ID 24 | - **valuetype** (String) Item Value Type, one of: float, character, log, unsigned, text 25 | 26 | ### Optional 27 | 28 | - **applications** (Set of String) Application IDs to associate this item with 29 | - **delay** (String) Item Delay period 30 | - **history** (String) Item History 31 | - **id** (String) The ID of this resource. 32 | - **interfaceid** (String) Host Interface ID 33 | - **preprocessor** (Block List) (see [below for nested schema](#nestedblock--preprocessor)) 34 | - **tag** (Block Set) (see [below for nested schema](#nestedblock--tag)) 35 | - **trends** (String) Item Trends 36 | 37 | 38 | ### Nested Schema for `preprocessor` 39 | 40 | Required: 41 | 42 | - **type** (String) Preprocessor type, zabbix identifier number 43 | 44 | Optional: 45 | 46 | - **error_handler** (String) 47 | - **error_handler_params** (String) 48 | - **params** (List of String) Preprocessor parameters 49 | 50 | Read-Only: 51 | 52 | - **id** (String) The ID of this resource. 53 | 54 | 55 | 56 | ### Nested Schema for `tag` 57 | 58 | Required: 59 | 60 | - **key** (String) Tag Key 61 | 62 | Optional: 63 | 64 | - **value** (String) Tag Value 65 | 66 | 67 | -------------------------------------------------------------------------------- /.github/workflows/release.yml: -------------------------------------------------------------------------------- 1 | # This GitHub action can publish assets for release when a tag is created. 2 | # Currently its setup to run on any tag that matches the pattern "v*" (ie. v0.1.0). 3 | # 4 | # This uses an action (hashicorp/ghaction-import-gpg) that assumes you set your 5 | # private key in the `GPG_PRIVATE_KEY` secret and passphrase in the `PASSPHRASE` 6 | # secret. If you would rather own your own GPG handling, please fork this action 7 | # or use an alternative one for key handling. 8 | # 9 | # You will need to pass the `--batch` flag to `gpg` in your signing step 10 | # in `goreleaser` to indicate this is being used in a non-interactive mode. 11 | # 12 | name: release 13 | on: 14 | push: 15 | tags: 16 | - 'v*' 17 | jobs: 18 | goreleaser: 19 | runs-on: ubuntu-latest 20 | steps: 21 | - 22 | name: Checkout 23 | uses: actions/checkout@v3 24 | with: 25 | fetch-depth: 0 26 | - 27 | name: Set up Go 28 | uses: actions/setup-go@v4 29 | with: 30 | go-version: 1.17 31 | - 32 | name: Import GPG key 33 | id: import_gpg 34 | uses: crazy-max/ghaction-import-gpg@v5 35 | with: 36 | # These secrets will need to be configured for the repository: 37 | gpg_private_key: ${{ secrets.GPG_PRIVATE_KEY }} 38 | passphrase: ${{ secrets.PASSPHRASE }} 39 | - 40 | name: Run GoReleaser 41 | uses: goreleaser/goreleaser-action@v4 42 | with: 43 | version: latest 44 | args: release --rm-dist --clean 45 | env: 46 | GPG_FINGERPRINT: ${{ steps.import_gpg.outputs.fingerprint }} 47 | # GitHub sets this automatically 48 | GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} 49 | -------------------------------------------------------------------------------- /.goreleaser.yml: -------------------------------------------------------------------------------- 1 | # Visit https://goreleaser.com for documentation on how to customize this 2 | # behavior. 3 | before: 4 | hooks: 5 | # this is just an example and not a requirement for provider building/publishing 6 | - go mod tidy 7 | builds: 8 | - env: 9 | # goreleaser does not work with CGO, it could also complicate 10 | # usage by users in CI/CD systems like Terraform Cloud where 11 | # they are unable to install libraries. 12 | - CGO_ENABLED=0 13 | mod_timestamp: '{{ .CommitTimestamp }}' 14 | flags: 15 | - -trimpath 16 | ldflags: 17 | - '-s -w -X main.version={{.Version}} -X main.commit={{.Commit}}' 18 | goos: 19 | - freebsd 20 | - windows 21 | - linux 22 | - darwin 23 | goarch: 24 | - amd64 25 | - '386' 26 | - arm 27 | - arm64 28 | ignore: 29 | - goos: darwin 30 | goarch: '386' 31 | - goos: windows 32 | goarch: 'arm64' 33 | binary: '{{ .ProjectName }}_v{{ .Version }}' 34 | archives: 35 | - format: zip 36 | name_template: '{{ .ProjectName }}_{{ .Version }}_{{ .Os }}_{{ .Arch }}' 37 | checksum: 38 | name_template: '{{ .ProjectName }}_{{ .Version }}_SHA256SUMS' 39 | algorithm: sha256 40 | signs: 41 | - artifacts: checksum 42 | args: 43 | # if you are using this in a GitHub action or some other automated pipeline, you 44 | # need to pass the batch flag to indicate its not interactive. 45 | - "--batch" 46 | - "--local-user" 47 | - "{{ .Env.GPG_FINGERPRINT }}" # set this environment variable for your signing key 48 | - "--output" 49 | - "${signature}" 50 | - "--detach-sign" 51 | - "${artifact}" 52 | release: 53 | # If you want to manually examine the release before its live, uncomment this line: 54 | # draft: true 55 | changelog: 56 | skip: true 57 | -------------------------------------------------------------------------------- /docs/resources/proto_item_agent.md: -------------------------------------------------------------------------------- 1 | --- 2 | # generated by https://github.com/hashicorp/terraform-plugin-docs 3 | page_title: "zabbix_proto_item_agent Resource - terraform-provider-zabbix" 4 | subcategory: "" 5 | description: |- 6 | 7 | --- 8 | 9 | # zabbix_proto_item_agent (Resource) 10 | 11 | 12 | 13 | 14 | 15 | 16 | ## Schema 17 | 18 | ### Required 19 | 20 | - **hostid** (String) Host ID 21 | - **key** (String) Item KEY 22 | - **name** (String) Item Name 23 | - **ruleid** (String) LLD Rule ID 24 | - **valuetype** (String) Item Value Type, one of: float, character, log, unsigned, text 25 | 26 | ### Optional 27 | 28 | - **active** (Boolean) Active zabbix agent Item 29 | - **applications** (Set of String) Application IDs to associate this item with 30 | - **delay** (String) Item Delay period 31 | - **history** (String) Item History 32 | - **id** (String) The ID of this resource. 33 | - **interfaceid** (String) Host Interface ID 34 | - **preprocessor** (Block List) (see [below for nested schema](#nestedblock--preprocessor)) 35 | - **tag** (Block Set) (see [below for nested schema](#nestedblock--tag)) 36 | - **trends** (String) Item Trends 37 | 38 | 39 | ### Nested Schema for `preprocessor` 40 | 41 | Required: 42 | 43 | - **type** (String) Preprocessor type, zabbix identifier number 44 | 45 | Optional: 46 | 47 | - **error_handler** (String) 48 | - **error_handler_params** (String) 49 | - **params** (List of String) Preprocessor parameters 50 | 51 | Read-Only: 52 | 53 | - **id** (String) The ID of this resource. 54 | 55 | 56 | 57 | ### Nested Schema for `tag` 58 | 59 | Required: 60 | 61 | - **key** (String) Tag Key 62 | 63 | Optional: 64 | 65 | - **value** (String) Tag Value 66 | 67 | 68 | -------------------------------------------------------------------------------- /docs/resources/graph.md: -------------------------------------------------------------------------------- 1 | --- 2 | # generated by https://github.com/hashicorp/terraform-plugin-docs 3 | page_title: "zabbix_graph Resource - terraform-provider-zabbix" 4 | subcategory: "" 5 | description: |- 6 | 7 | --- 8 | 9 | # zabbix_graph (Resource) 10 | 11 | 12 | 13 | 14 | 15 | 16 | ## Schema 17 | 18 | ### Required 19 | 20 | - **height** (String) Height 21 | - **item** (Block List, Min: 1) (see [below for nested schema](#nestedblock--item)) 22 | - **name** (String) Graph Name 23 | - **width** (String) Width 24 | 25 | ### Optional 26 | 27 | - **do3d** (Boolean) Show 3d graph 28 | - **id** (String) The ID of this resource. 29 | - **legend** (Boolean) Show legend 30 | - **percent_left** (String) Left percentile 31 | - **percent_right** (String) Right percentile 32 | - **type** (String) Type, one of: normal, stacked, pie, exploded 33 | - **work_period** (Boolean) Show work period 34 | - **ymax** (String) Y Axis Max 35 | - **ymax_itemid** (String) Y Axis Max ItemId 36 | - **ymax_type** (String) Y Axis Max Type, one of: calculated, fixed, item 37 | - **ymin** (String) Y Axis Min 38 | - **ymin_itemid** (String) Y Axis Min ItemId 39 | - **ymin_type** (String) Y Axis Min Type, one of: calculated, fixed, item 40 | 41 | 42 | ### Nested Schema for `item` 43 | 44 | Required: 45 | 46 | - **color** (String) color 47 | - **itemid** (String) itemid 48 | 49 | Optional: 50 | 51 | - **drawtype** (String) Draw Type, one of: line, filled, bold, dot, dashed, gradient 52 | - **function** (String) Function, one of: min, average, max, all, last 53 | - **sortorder** (String) sort order 54 | - **type** (String) Type, one of: simple, sum 55 | - **yaxis_side** (String) Y Axis Side, one of: left, right 56 | 57 | Read-Only: 58 | 59 | - **id** (String) The ID of this resource. 60 | 61 | 62 | -------------------------------------------------------------------------------- /docs/resources/proto_graph.md: -------------------------------------------------------------------------------- 1 | --- 2 | # generated by https://github.com/hashicorp/terraform-plugin-docs 3 | page_title: "zabbix_proto_graph Resource - terraform-provider-zabbix" 4 | subcategory: "" 5 | description: |- 6 | 7 | --- 8 | 9 | # zabbix_proto_graph (Resource) 10 | 11 | 12 | 13 | 14 | 15 | 16 | ## Schema 17 | 18 | ### Required 19 | 20 | - **height** (String) Height 21 | - **item** (Block List, Min: 1) (see [below for nested schema](#nestedblock--item)) 22 | - **name** (String) Graph Name 23 | - **width** (String) Width 24 | 25 | ### Optional 26 | 27 | - **do3d** (Boolean) Show 3d graph 28 | - **id** (String) The ID of this resource. 29 | - **legend** (Boolean) Show legend 30 | - **percent_left** (String) Left percentile 31 | - **percent_right** (String) Right percentile 32 | - **type** (String) Type, one of: normal, stacked, pie, exploded 33 | - **work_period** (Boolean) Show work period 34 | - **ymax** (String) Y Axis Max 35 | - **ymax_itemid** (String) Y Axis Max ItemId 36 | - **ymax_type** (String) Y Axis Max Type, one of: calculated, fixed, item 37 | - **ymin** (String) Y Axis Min 38 | - **ymin_itemid** (String) Y Axis Min ItemId 39 | - **ymin_type** (String) Y Axis Min Type, one of: calculated, fixed, item 40 | 41 | 42 | ### Nested Schema for `item` 43 | 44 | Required: 45 | 46 | - **color** (String) color 47 | - **itemid** (String) itemid 48 | 49 | Optional: 50 | 51 | - **drawtype** (String) Draw Type, one of: line, filled, bold, dot, dashed, gradient 52 | - **function** (String) Function, one of: min, average, max, all, last 53 | - **sortorder** (String) sort order 54 | - **type** (String) Type, one of: simple, sum 55 | - **yaxis_side** (String) Y Axis Side, one of: left, right 56 | 57 | Read-Only: 58 | 59 | - **id** (String) The ID of this resource. 60 | 61 | 62 | -------------------------------------------------------------------------------- /provider/utils.go: -------------------------------------------------------------------------------- 1 | package provider 2 | 3 | import ( 4 | "github.com/hashicorp/terraform-plugin-sdk/helper/schema" 5 | "github.com/tpretz/go-zabbix-api" 6 | ) 7 | 8 | func flattenHostGroupIds(list zabbix.HostGroupIDs) *schema.Set { 9 | s := schema.NewSet(schema.HashString, []interface{}{}) 10 | for _, v := range list { 11 | s.Add(v.GroupID) 12 | } 13 | return s 14 | } 15 | 16 | func flattenTemplateIds(list zabbix.TemplateIDs) *schema.Set { 17 | s := schema.NewSet(schema.HashString, []interface{}{}) 18 | for _, v := range list { 19 | s.Add(v.TemplateID) 20 | } 21 | return s 22 | } 23 | 24 | func buildHostGroupIds(s *schema.Set) zabbix.HostGroupIDs { 25 | list := s.List() 26 | 27 | groups := make(zabbix.HostGroupIDs, len(list)) 28 | 29 | for i := 0; i < len(list); i++ { 30 | groups[i] = zabbix.HostGroupID{ 31 | GroupID: list[i].(string), 32 | } 33 | } 34 | 35 | return groups 36 | } 37 | 38 | func buildTriggerIds(s *schema.Set) zabbix.TriggerIDs { 39 | list := s.List() 40 | 41 | groups := make(zabbix.TriggerIDs, len(list)) 42 | 43 | for i := 0; i < len(list); i++ { 44 | groups[i] = zabbix.TriggerID{ 45 | TriggerID: list[i].(string), 46 | } 47 | } 48 | 49 | return groups 50 | } 51 | 52 | func buildTemplateIds(s *schema.Set) zabbix.TemplateIDs { 53 | list := s.List() 54 | 55 | groups := make(zabbix.TemplateIDs, len(list)) 56 | 57 | for i := 0; i < len(list); i++ { 58 | groups[i] = zabbix.TemplateID{ 59 | TemplateID: list[i].(string), 60 | } 61 | } 62 | 63 | return groups 64 | } 65 | 66 | // mergeSchemas, take a varadic list of schemas and merge, latter overwrites former 67 | func mergeSchemas(schemas ...map[string]*schema.Schema) map[string]*schema.Schema { 68 | n := map[string]*schema.Schema{} 69 | 70 | for _, s := range schemas { 71 | for k, v := range s { 72 | n[k] = v 73 | } 74 | } 75 | 76 | return n 77 | } 78 | -------------------------------------------------------------------------------- /provider/common_macro.go: -------------------------------------------------------------------------------- 1 | package provider 2 | 3 | import ( 4 | "fmt" 5 | 6 | "github.com/hashicorp/terraform-plugin-sdk/helper/schema" 7 | "github.com/hashicorp/terraform-plugin-sdk/helper/validation" 8 | "github.com/tpretz/go-zabbix-api" 9 | ) 10 | 11 | // macro list schema 12 | var macroListSchema = &schema.Schema{ 13 | Type: schema.TypeList, 14 | Optional: true, 15 | Elem: &schema.Resource{ 16 | Schema: map[string]*schema.Schema{ 17 | "id": &schema.Schema{ 18 | Type: schema.TypeString, 19 | Computed: true, 20 | }, 21 | "name": &schema.Schema{ 22 | Type: schema.TypeString, 23 | Required: true, 24 | ValidateFunc: validation.StringIsNotWhiteSpace, 25 | Description: "Macro Name (key)", 26 | }, 27 | "value": &schema.Schema{ 28 | Type: schema.TypeString, 29 | Required: true, 30 | ValidateFunc: validation.StringIsNotWhiteSpace, 31 | Description: "Macro Value", 32 | }, 33 | }, 34 | }, 35 | } 36 | 37 | // macroGenerate build macro structs from terraform inputs 38 | func macroGenerate(d *schema.ResourceData) (macros zabbix.Macros) { 39 | macroCount := d.Get("macro.#").(int) 40 | macros = make(zabbix.Macros, macroCount) 41 | 42 | for i := 0; i < macroCount; i++ { 43 | prefix := fmt.Sprintf("macro.%d.", i) 44 | 45 | macros[i] = zabbix.Macro{ 46 | MacroName: d.Get(prefix + "name").(string), 47 | Value: d.Get(prefix + "value").(string), 48 | MacroID: d.Get(prefix + "id").(string), 49 | } 50 | } 51 | 52 | return 53 | } 54 | 55 | // flattenMacros convert response to terraform input 56 | func flattenMacros(list zabbix.Macros) []interface{} { 57 | val := make([]interface{}, len(list)) 58 | for i := 0; i < len(list); i++ { 59 | val[i] = map[string]interface{}{ 60 | "name": list[i].MacroName, 61 | "value": list[i].Value, 62 | "id": list[i].MacroID, 63 | } 64 | } 65 | return val 66 | } 67 | -------------------------------------------------------------------------------- /docs/resources/lld_trapper.md: -------------------------------------------------------------------------------- 1 | --- 2 | # generated by https://github.com/hashicorp/terraform-plugin-docs 3 | page_title: "zabbix_lld_trapper Resource - terraform-provider-zabbix" 4 | subcategory: "" 5 | description: |- 6 | 7 | --- 8 | 9 | # zabbix_lld_trapper (Resource) 10 | 11 | 12 | 13 | 14 | 15 | 16 | ## Schema 17 | 18 | ### Required 19 | 20 | - **hostid** (String) Host ID 21 | - **key** (String) LLD KEY 22 | - **name** (String) LLD Name 23 | 24 | ### Optional 25 | 26 | - **condition** (Block List) (see [below for nested schema](#nestedblock--condition)) 27 | - **delay** (String) LLD Delay period 28 | - **evaltype** (String) EvalType, one of: or, custom, andor, and 29 | - **formula** (String) Formula 30 | - **id** (String) The ID of this resource. 31 | - **lifetime** (String) LLD Stale Item Lifetime 32 | - **macro** (Block Set) (see [below for nested schema](#nestedblock--macro)) 33 | - **preprocessor** (Block List) (see [below for nested schema](#nestedblock--preprocessor)) 34 | 35 | 36 | ### Nested Schema for `condition` 37 | 38 | Required: 39 | 40 | - **macro** (String) Filter Macro 41 | - **value** (String) Filter Value 42 | 43 | Optional: 44 | 45 | - **operator** (String) Operator, one of: match, notmatch 46 | 47 | Read-Only: 48 | 49 | - **id** (String) The ID of this resource. 50 | 51 | 52 | 53 | ### Nested Schema for `macro` 54 | 55 | Required: 56 | 57 | - **macro** (String) Macro 58 | - **path** (String) Macro Path 59 | 60 | 61 | 62 | ### Nested Schema for `preprocessor` 63 | 64 | Required: 65 | 66 | - **type** (String) Preprocessor type, zabbix identifier number 67 | 68 | Optional: 69 | 70 | - **error_handler** (String) 71 | - **error_handler_params** (String) 72 | - **params** (List of String) Preprocessor parameters 73 | 74 | Read-Only: 75 | 76 | - **id** (String) The ID of this resource. 77 | 78 | 79 | -------------------------------------------------------------------------------- /docs/resources/lld_simple.md: -------------------------------------------------------------------------------- 1 | --- 2 | # generated by https://github.com/hashicorp/terraform-plugin-docs 3 | page_title: "zabbix_lld_simple Resource - terraform-provider-zabbix" 4 | subcategory: "" 5 | description: |- 6 | 7 | --- 8 | 9 | # zabbix_lld_simple (Resource) 10 | 11 | 12 | 13 | 14 | 15 | 16 | ## Schema 17 | 18 | ### Required 19 | 20 | - **hostid** (String) Host ID 21 | - **key** (String) LLD KEY 22 | - **name** (String) LLD Name 23 | 24 | ### Optional 25 | 26 | - **condition** (Block List) (see [below for nested schema](#nestedblock--condition)) 27 | - **delay** (String) LLD Delay period 28 | - **evaltype** (String) EvalType, one of: or, custom, andor, and 29 | - **formula** (String) Formula 30 | - **id** (String) The ID of this resource. 31 | - **interfaceid** (String) Host Interface ID 32 | - **lifetime** (String) LLD Stale Item Lifetime 33 | - **macro** (Block Set) (see [below for nested schema](#nestedblock--macro)) 34 | - **preprocessor** (Block List) (see [below for nested schema](#nestedblock--preprocessor)) 35 | 36 | 37 | ### Nested Schema for `condition` 38 | 39 | Required: 40 | 41 | - **macro** (String) Filter Macro 42 | - **value** (String) Filter Value 43 | 44 | Optional: 45 | 46 | - **operator** (String) Operator, one of: match, notmatch 47 | 48 | Read-Only: 49 | 50 | - **id** (String) The ID of this resource. 51 | 52 | 53 | 54 | ### Nested Schema for `macro` 55 | 56 | Required: 57 | 58 | - **macro** (String) Macro 59 | - **path** (String) Macro Path 60 | 61 | 62 | 63 | ### Nested Schema for `preprocessor` 64 | 65 | Required: 66 | 67 | - **type** (String) Preprocessor type, zabbix identifier number 68 | 69 | Optional: 70 | 71 | - **error_handler** (String) 72 | - **error_handler_params** (String) 73 | - **params** (List of String) Preprocessor parameters 74 | 75 | Read-Only: 76 | 77 | - **id** (String) The ID of this resource. 78 | 79 | 80 | -------------------------------------------------------------------------------- /docs/resources/lld_external.md: -------------------------------------------------------------------------------- 1 | --- 2 | # generated by https://github.com/hashicorp/terraform-plugin-docs 3 | page_title: "zabbix_lld_external Resource - terraform-provider-zabbix" 4 | subcategory: "" 5 | description: |- 6 | 7 | --- 8 | 9 | # zabbix_lld_external (Resource) 10 | 11 | 12 | 13 | 14 | 15 | 16 | ## Schema 17 | 18 | ### Required 19 | 20 | - **hostid** (String) Host ID 21 | - **key** (String) LLD KEY 22 | - **name** (String) LLD Name 23 | 24 | ### Optional 25 | 26 | - **condition** (Block List) (see [below for nested schema](#nestedblock--condition)) 27 | - **delay** (String) LLD Delay period 28 | - **evaltype** (String) EvalType, one of: or, custom, andor, and 29 | - **formula** (String) Formula 30 | - **id** (String) The ID of this resource. 31 | - **interfaceid** (String) Host Interface ID 32 | - **lifetime** (String) LLD Stale Item Lifetime 33 | - **macro** (Block Set) (see [below for nested schema](#nestedblock--macro)) 34 | - **preprocessor** (Block List) (see [below for nested schema](#nestedblock--preprocessor)) 35 | 36 | 37 | ### Nested Schema for `condition` 38 | 39 | Required: 40 | 41 | - **macro** (String) Filter Macro 42 | - **value** (String) Filter Value 43 | 44 | Optional: 45 | 46 | - **operator** (String) Operator, one of: match, notmatch 47 | 48 | Read-Only: 49 | 50 | - **id** (String) The ID of this resource. 51 | 52 | 53 | 54 | ### Nested Schema for `macro` 55 | 56 | Required: 57 | 58 | - **macro** (String) Macro 59 | - **path** (String) Macro Path 60 | 61 | 62 | 63 | ### Nested Schema for `preprocessor` 64 | 65 | Required: 66 | 67 | - **type** (String) Preprocessor type, zabbix identifier number 68 | 69 | Optional: 70 | 71 | - **error_handler** (String) 72 | - **error_handler_params** (String) 73 | - **params** (List of String) Preprocessor parameters 74 | 75 | Read-Only: 76 | 77 | - **id** (String) The ID of this resource. 78 | 79 | 80 | -------------------------------------------------------------------------------- /docs/resources/lld_internal.md: -------------------------------------------------------------------------------- 1 | --- 2 | # generated by https://github.com/hashicorp/terraform-plugin-docs 3 | page_title: "zabbix_lld_internal Resource - terraform-provider-zabbix" 4 | subcategory: "" 5 | description: |- 6 | 7 | --- 8 | 9 | # zabbix_lld_internal (Resource) 10 | 11 | 12 | 13 | 14 | 15 | 16 | ## Schema 17 | 18 | ### Required 19 | 20 | - **hostid** (String) Host ID 21 | - **key** (String) LLD KEY 22 | - **name** (String) LLD Name 23 | 24 | ### Optional 25 | 26 | - **condition** (Block List) (see [below for nested schema](#nestedblock--condition)) 27 | - **delay** (String) LLD Delay period 28 | - **evaltype** (String) EvalType, one of: or, custom, andor, and 29 | - **formula** (String) Formula 30 | - **id** (String) The ID of this resource. 31 | - **interfaceid** (String) Host Interface ID 32 | - **lifetime** (String) LLD Stale Item Lifetime 33 | - **macro** (Block Set) (see [below for nested schema](#nestedblock--macro)) 34 | - **preprocessor** (Block List) (see [below for nested schema](#nestedblock--preprocessor)) 35 | 36 | 37 | ### Nested Schema for `condition` 38 | 39 | Required: 40 | 41 | - **macro** (String) Filter Macro 42 | - **value** (String) Filter Value 43 | 44 | Optional: 45 | 46 | - **operator** (String) Operator, one of: match, notmatch 47 | 48 | Read-Only: 49 | 50 | - **id** (String) The ID of this resource. 51 | 52 | 53 | 54 | ### Nested Schema for `macro` 55 | 56 | Required: 57 | 58 | - **macro** (String) Macro 59 | - **path** (String) Macro Path 60 | 61 | 62 | 63 | ### Nested Schema for `preprocessor` 64 | 65 | Required: 66 | 67 | - **type** (String) Preprocessor type, zabbix identifier number 68 | 69 | Optional: 70 | 71 | - **error_handler** (String) 72 | - **error_handler_params** (String) 73 | - **params** (List of String) Preprocessor parameters 74 | 75 | Read-Only: 76 | 77 | - **id** (String) The ID of this resource. 78 | 79 | 80 | -------------------------------------------------------------------------------- /docs/resources/lld_dependent.md: -------------------------------------------------------------------------------- 1 | --- 2 | # generated by https://github.com/hashicorp/terraform-plugin-docs 3 | page_title: "zabbix_lld_dependent Resource - terraform-provider-zabbix" 4 | subcategory: "" 5 | description: |- 6 | 7 | --- 8 | 9 | # zabbix_lld_dependent (Resource) 10 | 11 | 12 | 13 | 14 | 15 | 16 | ## Schema 17 | 18 | ### Required 19 | 20 | - **hostid** (String) Host ID 21 | - **key** (String) LLD KEY 22 | - **master_itemid** (String) Master Item ID 23 | - **name** (String) LLD Name 24 | 25 | ### Optional 26 | 27 | - **condition** (Block List) (see [below for nested schema](#nestedblock--condition)) 28 | - **delay** (String) LLD Delay period 29 | - **evaltype** (String) EvalType, one of: or, custom, andor, and 30 | - **formula** (String) Formula 31 | - **id** (String) The ID of this resource. 32 | - **lifetime** (String) LLD Stale Item Lifetime 33 | - **macro** (Block Set) (see [below for nested schema](#nestedblock--macro)) 34 | - **preprocessor** (Block List) (see [below for nested schema](#nestedblock--preprocessor)) 35 | 36 | 37 | ### Nested Schema for `condition` 38 | 39 | Required: 40 | 41 | - **macro** (String) Filter Macro 42 | - **value** (String) Filter Value 43 | 44 | Optional: 45 | 46 | - **operator** (String) Operator, one of: match, notmatch 47 | 48 | Read-Only: 49 | 50 | - **id** (String) The ID of this resource. 51 | 52 | 53 | 54 | ### Nested Schema for `macro` 55 | 56 | Required: 57 | 58 | - **macro** (String) Macro 59 | - **path** (String) Macro Path 60 | 61 | 62 | 63 | ### Nested Schema for `preprocessor` 64 | 65 | Required: 66 | 67 | - **type** (String) Preprocessor type, zabbix identifier number 68 | 69 | Optional: 70 | 71 | - **error_handler** (String) 72 | - **error_handler_params** (String) 73 | - **params** (List of String) Preprocessor parameters 74 | 75 | Read-Only: 76 | 77 | - **id** (String) The ID of this resource. 78 | 79 | 80 | -------------------------------------------------------------------------------- /docs/resources/lld_agent.md: -------------------------------------------------------------------------------- 1 | --- 2 | # generated by https://github.com/hashicorp/terraform-plugin-docs 3 | page_title: "zabbix_lld_agent Resource - terraform-provider-zabbix" 4 | subcategory: "" 5 | description: |- 6 | 7 | --- 8 | 9 | # zabbix_lld_agent (Resource) 10 | 11 | 12 | 13 | 14 | 15 | 16 | ## Schema 17 | 18 | ### Required 19 | 20 | - **hostid** (String) Host ID 21 | - **key** (String) LLD KEY 22 | - **name** (String) LLD Name 23 | 24 | ### Optional 25 | 26 | - **active** (Boolean) Active zabbix agent Item 27 | - **condition** (Block List) (see [below for nested schema](#nestedblock--condition)) 28 | - **delay** (String) LLD Delay period 29 | - **evaltype** (String) EvalType, one of: or, custom, andor, and 30 | - **formula** (String) Formula 31 | - **id** (String) The ID of this resource. 32 | - **interfaceid** (String) Host Interface ID 33 | - **lifetime** (String) LLD Stale Item Lifetime 34 | - **macro** (Block Set) (see [below for nested schema](#nestedblock--macro)) 35 | - **preprocessor** (Block List) (see [below for nested schema](#nestedblock--preprocessor)) 36 | 37 | 38 | ### Nested Schema for `condition` 39 | 40 | Required: 41 | 42 | - **macro** (String) Filter Macro 43 | - **value** (String) Filter Value 44 | 45 | Optional: 46 | 47 | - **operator** (String) Operator, one of: match, notmatch 48 | 49 | Read-Only: 50 | 51 | - **id** (String) The ID of this resource. 52 | 53 | 54 | 55 | ### Nested Schema for `macro` 56 | 57 | Required: 58 | 59 | - **macro** (String) Macro 60 | - **path** (String) Macro Path 61 | 62 | 63 | 64 | ### Nested Schema for `preprocessor` 65 | 66 | Required: 67 | 68 | - **type** (String) Preprocessor type, zabbix identifier number 69 | 70 | Optional: 71 | 72 | - **error_handler** (String) 73 | - **error_handler_params** (String) 74 | - **params** (List of String) Preprocessor parameters 75 | 76 | Read-Only: 77 | 78 | - **id** (String) The ID of this resource. 79 | 80 | 81 | -------------------------------------------------------------------------------- /provider/resource_proxy.go: -------------------------------------------------------------------------------- 1 | package provider 2 | 3 | import ( 4 | "errors" 5 | 6 | "github.com/hashicorp/terraform-plugin-sdk/helper/schema" 7 | "github.com/hashicorp/terraform-plugin-sdk/helper/validation" 8 | 9 | "github.com/tpretz/go-zabbix-api" 10 | ) 11 | 12 | // proxySchemaBase base proxy schema 13 | var proxySchemaBase = map[string]*schema.Schema{ 14 | "host": &schema.Schema{ 15 | Type: schema.TypeString, 16 | Description: "FQDN of proxy", 17 | ValidateFunc: validation.StringIsNotWhiteSpace, 18 | Required: true, 19 | }, 20 | } 21 | 22 | // dataProxy terraform proxy resource entrypoint 23 | func dataProxy() *schema.Resource { 24 | return &schema.Resource{ 25 | Read: dataProxyRead, 26 | Schema: proxySchemaBase, 27 | } 28 | } 29 | 30 | // dataProxyRead read handler for data resource 31 | func dataProxyRead(d *schema.ResourceData, m interface{}) error { 32 | params := zabbix.Params{ 33 | "selectInterface": "extend", 34 | "filter": map[string]interface{}{}, 35 | } 36 | 37 | lookups := []string{"host"} 38 | for _, k := range lookups { 39 | if v, ok := d.GetOk(k); ok { 40 | params["filter"].(map[string]interface{})[k] = v 41 | } 42 | } 43 | 44 | if len(params["filter"].(map[string]interface{})) < 1 { 45 | return errors.New("no proxy lookup attribute") 46 | } 47 | log.Debug("performing data lookup with params: %#v", params) 48 | 49 | return proxyRead(d, m, params) 50 | } 51 | 52 | // proxyRead common proxy read function 53 | func proxyRead(d *schema.ResourceData, m interface{}, params zabbix.Params) error { 54 | api := m.(*zabbix.API) 55 | 56 | log.Debug("Lookup of proxy with params %#v", params) 57 | 58 | proxys, err := api.ProxiesGet(params) 59 | 60 | if err != nil { 61 | return err 62 | } 63 | 64 | if len(proxys) < 1 { 65 | d.SetId("") 66 | return nil 67 | } 68 | if len(proxys) > 1 { 69 | return errors.New("multiple proxys found") 70 | } 71 | proxy := proxys[0] 72 | 73 | log.Debug("Got proxy: %+v", proxy) 74 | 75 | d.SetId(proxy.ProxyID) 76 | d.Set("host", proxy.Host) 77 | 78 | return nil 79 | } 80 | -------------------------------------------------------------------------------- /provider/resource_calculated_common.go: -------------------------------------------------------------------------------- 1 | package provider 2 | 3 | import ( 4 | "github.com/hashicorp/terraform-plugin-sdk/helper/schema" 5 | "github.com/hashicorp/terraform-plugin-sdk/helper/validation" 6 | "github.com/tpretz/go-zabbix-api" 7 | ) 8 | 9 | var schemaCalculated = map[string]*schema.Schema{ 10 | "formula": &schema.Schema{ 11 | Type: schema.TypeString, 12 | Required: true, 13 | Description: "Formula", 14 | ValidateFunc: validation.StringIsNotWhiteSpace, 15 | }, 16 | } 17 | 18 | // terraform resource handler for item type 19 | func resourceItemCalculated() *schema.Resource { 20 | return &schema.Resource{ 21 | Create: itemGetCreateWrapper(itemCalculatedModFunc, itemCalculatedReadFunc), 22 | Read: itemGetReadWrapper(itemCalculatedReadFunc), 23 | Update: itemGetUpdateWrapper(itemCalculatedModFunc, itemCalculatedReadFunc), 24 | Delete: resourceItemDelete, 25 | Importer: &schema.ResourceImporter{ 26 | State: schema.ImportStatePassthrough, 27 | }, 28 | 29 | Schema: mergeSchemas(itemCommonSchema, itemDelaySchema, schemaCalculated), 30 | } 31 | } 32 | func resourceProtoItemCalculated() *schema.Resource { 33 | return &schema.Resource{ 34 | Create: protoItemGetCreateWrapper(itemCalculatedModFunc, itemCalculatedReadFunc), 35 | Read: protoItemGetReadWrapper(itemCalculatedReadFunc), 36 | Update: protoItemGetUpdateWrapper(itemCalculatedModFunc, itemCalculatedReadFunc), 37 | Delete: resourceProtoItemDelete, 38 | Importer: &schema.ResourceImporter{ 39 | State: schema.ImportStatePassthrough, 40 | }, 41 | 42 | Schema: mergeSchemas(itemCommonSchema, itemDelaySchema, itemPrototypeSchema, schemaCalculated), 43 | } 44 | } 45 | 46 | // Custom mod handler for item type 47 | func itemCalculatedModFunc(d *schema.ResourceData, m interface{}, item *zabbix.Item) { 48 | item.Type = zabbix.Calculated 49 | item.Delay = d.Get("delay").(string) 50 | item.Params = d.Get("formula").(string) 51 | } 52 | 53 | // Custom read handler for item type 54 | func itemCalculatedReadFunc(d *schema.ResourceData, m interface{}, item *zabbix.Item) { 55 | d.Set("delay", item.Delay) 56 | d.Set("formula", item.Params) 57 | } 58 | -------------------------------------------------------------------------------- /provider/resource_trapper_common.go: -------------------------------------------------------------------------------- 1 | package provider 2 | 3 | import ( 4 | "github.com/hashicorp/terraform-plugin-sdk/helper/schema" 5 | "github.com/tpretz/go-zabbix-api" 6 | ) 7 | 8 | // terraform resource handler for item type 9 | func resourceItemTrapper() *schema.Resource { 10 | return &schema.Resource{ 11 | Create: itemGetCreateWrapper(itemTrapperModFunc, itemTrapperReadFunc), 12 | Read: itemGetReadWrapper(itemTrapperReadFunc), 13 | Update: itemGetUpdateWrapper(itemTrapperModFunc, itemTrapperReadFunc), 14 | Delete: resourceItemDelete, 15 | Importer: &schema.ResourceImporter{ 16 | State: schema.ImportStatePassthrough, 17 | }, 18 | 19 | Schema: itemCommonSchema, 20 | } 21 | } 22 | func resourceProtoItemTrapper() *schema.Resource { 23 | return &schema.Resource{ 24 | Create: protoItemGetCreateWrapper(itemTrapperModFunc, itemTrapperReadFunc), 25 | Read: protoItemGetReadWrapper(itemTrapperReadFunc), 26 | Update: protoItemGetUpdateWrapper(itemTrapperModFunc, itemTrapperReadFunc), 27 | Delete: resourceProtoItemDelete, 28 | Importer: &schema.ResourceImporter{ 29 | State: schema.ImportStatePassthrough, 30 | }, 31 | 32 | Schema: mergeSchemas(itemCommonSchema, itemPrototypeSchema), 33 | } 34 | } 35 | func resourceLLDTrapper() *schema.Resource { 36 | return &schema.Resource{ 37 | Create: lldGetCreateWrapper(lldTrapperModFunc, lldTrapperReadFunc), 38 | Read: lldGetReadWrapper(lldTrapperReadFunc), 39 | Update: lldGetUpdateWrapper(lldTrapperModFunc, lldTrapperReadFunc), 40 | Delete: resourceLLDDelete, 41 | Importer: &schema.ResourceImporter{ 42 | State: schema.ImportStatePassthrough, 43 | }, 44 | 45 | Schema: lldCommonSchema, 46 | } 47 | } 48 | 49 | // Custom mod handler for item type 50 | func itemTrapperModFunc(d *schema.ResourceData, m interface{}, item *zabbix.Item) { 51 | item.Type = zabbix.ZabbixTrapper 52 | } 53 | func lldTrapperModFunc(d *schema.ResourceData, m interface{}, item *zabbix.LLDRule) { 54 | item.Type = zabbix.ZabbixTrapper 55 | } 56 | 57 | // Custom read handler for item type 58 | func itemTrapperReadFunc(d *schema.ResourceData, m interface{}, item *zabbix.Item) { 59 | } 60 | func lldTrapperReadFunc(d *schema.ResourceData, m interface{}, item *zabbix.LLDRule) { 61 | } 62 | -------------------------------------------------------------------------------- /provider/resource_host_test.go: -------------------------------------------------------------------------------- 1 | package provider 2 | 3 | import ( 4 | "github.com/hashicorp/terraform-plugin-sdk/helper/resource" 5 | "testing" 6 | ) 7 | 8 | func TestAccResourceHost(t *testing.T) { 9 | 10 | resource.Test(t, resource.TestCase{ 11 | PreCheck: func() { 12 | testAccPreCheck(t) 13 | }, 14 | Providers: testAccProviders, 15 | Steps: []resource.TestStep{ 16 | { 17 | Config: testAccResourceHostBasic(), 18 | Check: resource.ComposeTestCheckFunc( 19 | resource.TestCheckResourceAttr("zabbix_host.testhost", "host", "test-host"), 20 | ), 21 | }, 22 | { 23 | Config: testAccResourceHostWithInventory(), 24 | Check: resource.ComposeTestCheckFunc( 25 | resource.TestCheckResourceAttr("zabbix_host.testhost2", "inventory_location", "test location A"), 26 | ), 27 | }, 28 | { 29 | Config: testAccResourceHostWithInventoryUpdate(), 30 | Check: resource.ComposeTestCheckFunc( 31 | resource.TestCheckResourceAttr("zabbix_host.testhost2", "inventory_location", "test location B"), 32 | ), 33 | }, 34 | }, 35 | }) 36 | } 37 | 38 | func testAccResourceHostBasic() string { 39 | return ` 40 | resource "zabbix_hostgroup" "testgrp" { 41 | name = "test-group" 42 | } 43 | resource "zabbix_host" "testhost" { 44 | host = "test-host" 45 | groups = [zabbix_hostgroup.testgrp.id] 46 | interface { 47 | type = "snmp" 48 | ip = "127.0.0.1" 49 | } 50 | } 51 | ` 52 | } 53 | 54 | func testAccResourceHostWithInventory() string { 55 | return ` 56 | resource "zabbix_hostgroup" "testgrp2" { 57 | name = "test-group2" 58 | } 59 | resource "zabbix_host" "testhost2" { 60 | host = "test-host2" 61 | groups = [zabbix_hostgroup.testgrp2.id] 62 | interface { 63 | type = "snmp" 64 | ip = "127.0.0.1" 65 | } 66 | inventory_location = "test location A" 67 | } 68 | ` 69 | } 70 | 71 | func testAccResourceHostWithInventoryUpdate() string { 72 | return ` 73 | resource "zabbix_hostgroup" "testgrp2" { 74 | name = "test-group2" 75 | } 76 | resource "zabbix_host" "testhost2" { 77 | host = "test-host2" 78 | groups = [zabbix_hostgroup.testgrp2.id] 79 | interface { 80 | type = "snmp" 81 | ip = "127.0.0.1" 82 | } 83 | inventory_location = "test location B" 84 | } 85 | ` 86 | } 87 | -------------------------------------------------------------------------------- /docs/resources/item_snmp.md: -------------------------------------------------------------------------------- 1 | --- 2 | # generated by https://github.com/hashicorp/terraform-plugin-docs 3 | page_title: "zabbix_item_snmp Resource - terraform-provider-zabbix" 4 | subcategory: "" 5 | description: |- 6 | 7 | --- 8 | 9 | # zabbix_item_snmp (Resource) 10 | 11 | 12 | 13 | 14 | 15 | 16 | ## Schema 17 | 18 | ### Required 19 | 20 | - **hostid** (String) Host ID 21 | - **key** (String) Item KEY 22 | - **name** (String) Item Name 23 | - **snmp_oid** (String) SNMP OID 24 | - **valuetype** (String) Item Value Type, one of: float, character, log, unsigned, text 25 | 26 | ### Optional 27 | 28 | - **applications** (Set of String) Application IDs to associate this item with 29 | - **delay** (String) Item Delay period 30 | - **history** (String) Item History 31 | - **id** (String) The ID of this resource. 32 | - **interfaceid** (String) Host Interface ID 33 | - **preprocessor** (Block List) (see [below for nested schema](#nestedblock--preprocessor)) 34 | - **snmp3_authpassphrase** (String) Authentication Passphrase (v3 only) 35 | - **snmp3_authprotocol** (String) Authentication Protocol (v3 only), one of: md5, sha 36 | - **snmp3_contextname** (String) Context Name (v3 only) 37 | - **snmp3_privpassphrase** (String) Priv Passphrase (v3 only) 38 | - **snmp3_privprotocol** (String) Priv Protocol (v3 only), one of: aes, des 39 | - **snmp3_securitylevel** (String) Security Level (v3 only), one of: noauthnopriv, authnopriv, authpriv 40 | - **snmp3_securityname** (String) Security Name (v3 only) 41 | - **snmp_community** (String) SNMP Community (v1/v2 only) 42 | - **snmp_version** (String) SNMP Version, one of: 1, 2, 3 43 | - **tag** (Block Set) (see [below for nested schema](#nestedblock--tag)) 44 | - **trends** (String) Item Trends 45 | 46 | 47 | ### Nested Schema for `preprocessor` 48 | 49 | Required: 50 | 51 | - **type** (String) Preprocessor type, zabbix identifier number 52 | 53 | Optional: 54 | 55 | - **error_handler** (String) 56 | - **error_handler_params** (String) 57 | - **params** (List of String) Preprocessor parameters 58 | 59 | Read-Only: 60 | 61 | - **id** (String) The ID of this resource. 62 | 63 | 64 | 65 | ### Nested Schema for `tag` 66 | 67 | Required: 68 | 69 | - **key** (String) Tag Key 70 | 71 | Optional: 72 | 73 | - **value** (String) Tag Value 74 | 75 | 76 | -------------------------------------------------------------------------------- /docs/resources/proto_item_snmp.md: -------------------------------------------------------------------------------- 1 | --- 2 | # generated by https://github.com/hashicorp/terraform-plugin-docs 3 | page_title: "zabbix_proto_item_snmp Resource - terraform-provider-zabbix" 4 | subcategory: "" 5 | description: |- 6 | 7 | --- 8 | 9 | # zabbix_proto_item_snmp (Resource) 10 | 11 | 12 | 13 | 14 | 15 | 16 | ## Schema 17 | 18 | ### Required 19 | 20 | - **hostid** (String) Host ID 21 | - **key** (String) Item KEY 22 | - **name** (String) Item Name 23 | - **ruleid** (String) LLD Rule ID 24 | - **snmp_oid** (String) SNMP OID 25 | - **valuetype** (String) Item Value Type, one of: float, character, log, unsigned, text 26 | 27 | ### Optional 28 | 29 | - **applications** (Set of String) Application IDs to associate this item with 30 | - **delay** (String) Item Delay period 31 | - **history** (String) Item History 32 | - **id** (String) The ID of this resource. 33 | - **interfaceid** (String) Host Interface ID 34 | - **preprocessor** (Block List) (see [below for nested schema](#nestedblock--preprocessor)) 35 | - **snmp3_authpassphrase** (String) Authentication Passphrase (v3 only) 36 | - **snmp3_authprotocol** (String) Authentication Protocol (v3 only), one of: md5, sha 37 | - **snmp3_contextname** (String) Context Name (v3 only) 38 | - **snmp3_privpassphrase** (String) Priv Passphrase (v3 only) 39 | - **snmp3_privprotocol** (String) Priv Protocol (v3 only), one of: aes, des 40 | - **snmp3_securitylevel** (String) Security Level (v3 only), one of: noauthnopriv, authnopriv, authpriv 41 | - **snmp3_securityname** (String) Security Name (v3 only) 42 | - **snmp_community** (String) SNMP Community (v1/v2 only) 43 | - **snmp_version** (String) SNMP Version, one of: 1, 2, 3 44 | - **tag** (Block Set) (see [below for nested schema](#nestedblock--tag)) 45 | - **trends** (String) Item Trends 46 | 47 | 48 | ### Nested Schema for `preprocessor` 49 | 50 | Required: 51 | 52 | - **type** (String) Preprocessor type, zabbix identifier number 53 | 54 | Optional: 55 | 56 | - **error_handler** (String) 57 | - **error_handler_params** (String) 58 | - **params** (List of String) Preprocessor parameters 59 | 60 | Read-Only: 61 | 62 | - **id** (String) The ID of this resource. 63 | 64 | 65 | 66 | ### Nested Schema for `tag` 67 | 68 | Required: 69 | 70 | - **key** (String) Tag Key 71 | 72 | Optional: 73 | 74 | - **value** (String) Tag Value 75 | 76 | 77 | -------------------------------------------------------------------------------- /docs/resources/item_http.md: -------------------------------------------------------------------------------- 1 | --- 2 | # generated by https://github.com/hashicorp/terraform-plugin-docs 3 | page_title: "zabbix_item_http Resource - terraform-provider-zabbix" 4 | subcategory: "" 5 | description: |- 6 | 7 | --- 8 | 9 | # zabbix_item_http (Resource) 10 | 11 | 12 | 13 | 14 | 15 | 16 | ## Schema 17 | 18 | ### Required 19 | 20 | - **hostid** (String) Host ID 21 | - **key** (String) Item KEY 22 | - **name** (String) Item Name 23 | - **url** (String) url to probe 24 | - **valuetype** (String) Item Value Type, one of: float, character, log, unsigned, text 25 | 26 | ### Optional 27 | 28 | - **applications** (Set of String) Application IDs to associate this item with 29 | - **auth_type** (String) HTTP auth type, one of: basic, ntlm, kerberos, none 30 | - **delay** (String) Item Delay period 31 | - **follow_redirects** (Boolean) follow http redirects 32 | - **headers** (Map of String) 33 | - **history** (String) Item History 34 | - **id** (String) The ID of this resource. 35 | - **interfaceid** (String) Host Interface ID 36 | - **password** (String, Sensitive) Authentication Password 37 | - **post_type** (String) HTTP post type, one of: xml, raw, json 38 | - **posts** (String) POST data to send in request 39 | - **preprocessor** (Block List) (see [below for nested schema](#nestedblock--preprocessor)) 40 | - **proxy** (String) HTTP proxy connection string 41 | - **request_method** (String) HTTP request method, one of: get, post, put, head 42 | - **retrieve_mode** (String) HTTP retrieve mode, one of: body, headers, both 43 | - **status_codes** (String) http status code 44 | - **tag** (Block Set) (see [below for nested schema](#nestedblock--tag)) 45 | - **timeout** (String) http request timeout 46 | - **trends** (String) Item Trends 47 | - **username** (String) Authentication Username 48 | - **verify_host** (Boolean) https verify host 49 | - **verify_peer** (Boolean) https verify peer 50 | 51 | 52 | ### Nested Schema for `preprocessor` 53 | 54 | Required: 55 | 56 | - **type** (String) Preprocessor type, zabbix identifier number 57 | 58 | Optional: 59 | 60 | - **error_handler** (String) 61 | - **error_handler_params** (String) 62 | - **params** (List of String) Preprocessor parameters 63 | 64 | Read-Only: 65 | 66 | - **id** (String) The ID of this resource. 67 | 68 | 69 | 70 | ### Nested Schema for `tag` 71 | 72 | Required: 73 | 74 | - **key** (String) Tag Key 75 | 76 | Optional: 77 | 78 | - **value** (String) Tag Value 79 | 80 | 81 | -------------------------------------------------------------------------------- /provider/resource_simple_common.go: -------------------------------------------------------------------------------- 1 | package provider 2 | 3 | import ( 4 | "github.com/hashicorp/terraform-plugin-sdk/helper/schema" 5 | "github.com/tpretz/go-zabbix-api" 6 | ) 7 | 8 | // terraform resource handler for item type 9 | func resourceItemSimple() *schema.Resource { 10 | return &schema.Resource{ 11 | Create: itemGetCreateWrapper(itemSimpleModFunc, itemSimpleReadFunc), 12 | Read: itemGetReadWrapper(itemSimpleReadFunc), 13 | Update: itemGetUpdateWrapper(itemSimpleModFunc, itemSimpleReadFunc), 14 | Delete: resourceItemDelete, 15 | Importer: &schema.ResourceImporter{ 16 | State: schema.ImportStatePassthrough, 17 | }, 18 | 19 | Schema: mergeSchemas(itemCommonSchema, itemDelaySchema, itemInterfaceSchema), 20 | } 21 | } 22 | func resourceProtoItemSimple() *schema.Resource { 23 | return &schema.Resource{ 24 | Create: protoItemGetCreateWrapper(itemSimpleModFunc, itemSimpleReadFunc), 25 | Read: protoItemGetReadWrapper(itemSimpleReadFunc), 26 | Update: protoItemGetUpdateWrapper(itemSimpleModFunc, itemSimpleReadFunc), 27 | Delete: resourceProtoItemDelete, 28 | Importer: &schema.ResourceImporter{ 29 | State: schema.ImportStatePassthrough, 30 | }, 31 | 32 | Schema: mergeSchemas(itemCommonSchema, itemDelaySchema, itemInterfaceSchema, itemPrototypeSchema), 33 | } 34 | } 35 | func resourceLLDSimple() *schema.Resource { 36 | return &schema.Resource{ 37 | Create: lldGetCreateWrapper(lldSimpleModFunc, lldSimpleReadFunc), 38 | Read: lldGetReadWrapper(lldSimpleReadFunc), 39 | Update: lldGetUpdateWrapper(lldSimpleModFunc, lldSimpleReadFunc), 40 | Delete: resourceLLDDelete, 41 | Importer: &schema.ResourceImporter{ 42 | State: schema.ImportStatePassthrough, 43 | }, 44 | 45 | Schema: mergeSchemas(lldCommonSchema, itemInterfaceSchema), 46 | } 47 | } 48 | 49 | // Custom mod handler for item type 50 | func itemSimpleModFunc(d *schema.ResourceData, m interface{}, item *zabbix.Item) { 51 | item.Delay = d.Get("delay").(string) 52 | item.Type = zabbix.SimpleCheck 53 | item.InterfaceID = d.Get("interfaceid").(string) 54 | } 55 | func lldSimpleModFunc(d *schema.ResourceData, m interface{}, item *zabbix.LLDRule) { 56 | item.Type = zabbix.SimpleCheck 57 | item.InterfaceID = d.Get("interfaceid").(string) 58 | } 59 | 60 | // Custom read handler for item type 61 | func itemSimpleReadFunc(d *schema.ResourceData, m interface{}, item *zabbix.Item) { 62 | d.Set("interfaceid", item.InterfaceID) 63 | d.Set("delay", item.Delay) 64 | } 65 | func lldSimpleReadFunc(d *schema.ResourceData, m interface{}, item *zabbix.LLDRule) { 66 | d.Set("interfaceid", item.InterfaceID) 67 | } 68 | -------------------------------------------------------------------------------- /docs/resources/proto_item_http.md: -------------------------------------------------------------------------------- 1 | --- 2 | # generated by https://github.com/hashicorp/terraform-plugin-docs 3 | page_title: "zabbix_proto_item_http Resource - terraform-provider-zabbix" 4 | subcategory: "" 5 | description: |- 6 | 7 | --- 8 | 9 | # zabbix_proto_item_http (Resource) 10 | 11 | 12 | 13 | 14 | 15 | 16 | ## Schema 17 | 18 | ### Required 19 | 20 | - **hostid** (String) Host ID 21 | - **key** (String) Item KEY 22 | - **name** (String) Item Name 23 | - **ruleid** (String) LLD Rule ID 24 | - **url** (String) url to probe 25 | - **valuetype** (String) Item Value Type, one of: float, character, log, unsigned, text 26 | 27 | ### Optional 28 | 29 | - **applications** (Set of String) Application IDs to associate this item with 30 | - **auth_type** (String) HTTP auth type, one of: basic, ntlm, kerberos, none 31 | - **delay** (String) Item Delay period 32 | - **follow_redirects** (Boolean) follow http redirects 33 | - **headers** (Map of String) 34 | - **history** (String) Item History 35 | - **id** (String) The ID of this resource. 36 | - **interfaceid** (String) Host Interface ID 37 | - **password** (String, Sensitive) Authentication Password 38 | - **post_type** (String) HTTP post type, one of: xml, raw, json 39 | - **posts** (String) POST data to send in request 40 | - **preprocessor** (Block List) (see [below for nested schema](#nestedblock--preprocessor)) 41 | - **proxy** (String) HTTP proxy connection string 42 | - **request_method** (String) HTTP request method, one of: get, post, put, head 43 | - **retrieve_mode** (String) HTTP retrieve mode, one of: body, headers, both 44 | - **status_codes** (String) http status code 45 | - **tag** (Block Set) (see [below for nested schema](#nestedblock--tag)) 46 | - **timeout** (String) http request timeout 47 | - **trends** (String) Item Trends 48 | - **username** (String) Authentication Username 49 | - **verify_host** (Boolean) https verify host 50 | - **verify_peer** (Boolean) https verify peer 51 | 52 | 53 | ### Nested Schema for `preprocessor` 54 | 55 | Required: 56 | 57 | - **type** (String) Preprocessor type, zabbix identifier number 58 | 59 | Optional: 60 | 61 | - **error_handler** (String) 62 | - **error_handler_params** (String) 63 | - **params** (List of String) Preprocessor parameters 64 | 65 | Read-Only: 66 | 67 | - **id** (String) The ID of this resource. 68 | 69 | 70 | 71 | ### Nested Schema for `tag` 72 | 73 | Required: 74 | 75 | - **key** (String) Tag Key 76 | 77 | Optional: 78 | 79 | - **value** (String) Tag Value 80 | 81 | 82 | -------------------------------------------------------------------------------- /provider/resource_external_common.go: -------------------------------------------------------------------------------- 1 | package provider 2 | 3 | import ( 4 | "github.com/hashicorp/terraform-plugin-sdk/helper/schema" 5 | "github.com/tpretz/go-zabbix-api" 6 | ) 7 | 8 | // terraform resource handler for item type 9 | func resourceItemExternal() *schema.Resource { 10 | return &schema.Resource{ 11 | Create: itemGetCreateWrapper(itemExternalModFunc, itemExternalReadFunc), 12 | Read: itemGetReadWrapper(itemExternalReadFunc), 13 | Update: itemGetUpdateWrapper(itemExternalModFunc, itemExternalReadFunc), 14 | Delete: resourceItemDelete, 15 | Importer: &schema.ResourceImporter{ 16 | State: schema.ImportStatePassthrough, 17 | }, 18 | 19 | Schema: mergeSchemas(itemCommonSchema, itemDelaySchema, itemInterfaceSchema), 20 | } 21 | } 22 | func resourceProtoItemExternal() *schema.Resource { 23 | return &schema.Resource{ 24 | Create: protoItemGetCreateWrapper(itemExternalModFunc, itemExternalReadFunc), 25 | Read: protoItemGetReadWrapper(itemExternalReadFunc), 26 | Update: protoItemGetUpdateWrapper(itemExternalModFunc, itemExternalReadFunc), 27 | Delete: resourceProtoItemDelete, 28 | Importer: &schema.ResourceImporter{ 29 | State: schema.ImportStatePassthrough, 30 | }, 31 | 32 | Schema: mergeSchemas(itemCommonSchema, itemDelaySchema, itemInterfaceSchema, itemPrototypeSchema), 33 | } 34 | } 35 | func resourceLLDExternal() *schema.Resource { 36 | return &schema.Resource{ 37 | Create: lldGetCreateWrapper(lldExternalModFunc, lldExternalReadFunc), 38 | Read: lldGetReadWrapper(lldExternalReadFunc), 39 | Update: lldGetUpdateWrapper(lldExternalModFunc, lldExternalReadFunc), 40 | Delete: resourceLLDDelete, 41 | Importer: &schema.ResourceImporter{ 42 | State: schema.ImportStatePassthrough, 43 | }, 44 | 45 | Schema: mergeSchemas(lldCommonSchema, itemInterfaceSchema), 46 | } 47 | } 48 | 49 | // Custom mod handler for item type 50 | func itemExternalModFunc(d *schema.ResourceData, m interface{}, item *zabbix.Item) { 51 | item.Type = zabbix.ExternalCheck 52 | item.InterfaceID = d.Get("interfaceid").(string) 53 | item.Delay = d.Get("delay").(string) 54 | } 55 | func lldExternalModFunc(d *schema.ResourceData, m interface{}, item *zabbix.LLDRule) { 56 | item.Type = zabbix.ExternalCheck 57 | item.InterfaceID = d.Get("interfaceid").(string) 58 | } 59 | 60 | // Custom read handler for item type 61 | func itemExternalReadFunc(d *schema.ResourceData, m interface{}, item *zabbix.Item) { 62 | d.Set("interfaceid", item.InterfaceID) 63 | d.Set("delay", item.Delay) 64 | } 65 | func lldExternalReadFunc(d *schema.ResourceData, m interface{}, item *zabbix.LLDRule) { 66 | d.Set("interfaceid", item.InterfaceID) 67 | } 68 | -------------------------------------------------------------------------------- /provider/resource_internal_common.go: -------------------------------------------------------------------------------- 1 | package provider 2 | 3 | import ( 4 | "github.com/hashicorp/terraform-plugin-sdk/helper/schema" 5 | "github.com/tpretz/go-zabbix-api" 6 | ) 7 | 8 | // terraform resource handler for item type 9 | func resourceItemInternal() *schema.Resource { 10 | return &schema.Resource{ 11 | Create: itemGetCreateWrapper(itemInternalModFunc, itemInternalReadFunc), 12 | Read: itemGetReadWrapper(itemInternalReadFunc), 13 | Update: itemGetUpdateWrapper(itemInternalModFunc, itemInternalReadFunc), 14 | Delete: resourceItemDelete, 15 | Importer: &schema.ResourceImporter{ 16 | State: schema.ImportStatePassthrough, 17 | }, 18 | 19 | Schema: mergeSchemas(itemCommonSchema, itemDelaySchema, itemInterfaceSchema), 20 | } 21 | } 22 | func resourceProtoItemInternal() *schema.Resource { 23 | return &schema.Resource{ 24 | Create: protoItemGetCreateWrapper(itemInternalModFunc, itemInternalReadFunc), 25 | Read: protoItemGetReadWrapper(itemInternalReadFunc), 26 | Update: protoItemGetUpdateWrapper(itemInternalModFunc, itemInternalReadFunc), 27 | Delete: resourceProtoItemDelete, 28 | Importer: &schema.ResourceImporter{ 29 | State: schema.ImportStatePassthrough, 30 | }, 31 | 32 | Schema: mergeSchemas(itemCommonSchema, itemDelaySchema, itemInterfaceSchema, itemPrototypeSchema), 33 | } 34 | } 35 | func resourceLLDInternal() *schema.Resource { 36 | return &schema.Resource{ 37 | Create: lldGetCreateWrapper(lldInternalModFunc, lldInternalReadFunc), 38 | Read: lldGetReadWrapper(lldInternalReadFunc), 39 | Update: lldGetUpdateWrapper(lldInternalModFunc, lldInternalReadFunc), 40 | Delete: resourceLLDDelete, 41 | Importer: &schema.ResourceImporter{ 42 | State: schema.ImportStatePassthrough, 43 | }, 44 | 45 | Schema: mergeSchemas(lldCommonSchema, itemInterfaceSchema), 46 | } 47 | } 48 | 49 | // Custom mod handler for item type 50 | func itemInternalModFunc(d *schema.ResourceData, m interface{}, item *zabbix.Item) { 51 | item.Type = zabbix.ZabbixInternal 52 | item.InterfaceID = d.Get("interfaceid").(string) 53 | item.Delay = d.Get("delay").(string) 54 | } 55 | func lldInternalModFunc(d *schema.ResourceData, m interface{}, item *zabbix.LLDRule) { 56 | item.Type = zabbix.ZabbixInternal 57 | item.InterfaceID = d.Get("interfaceid").(string) 58 | } 59 | 60 | // Custom read handler for item type 61 | func itemInternalReadFunc(d *schema.ResourceData, m interface{}, item *zabbix.Item) { 62 | d.Set("interfaceid", item.InterfaceID) 63 | d.Set("delay", item.Delay) 64 | } 65 | func lldInternalReadFunc(d *schema.ResourceData, m interface{}, item *zabbix.LLDRule) { 66 | d.Set("interfaceid", item.InterfaceID) 67 | } 68 | -------------------------------------------------------------------------------- /docs/resources/lld_snmp.md: -------------------------------------------------------------------------------- 1 | --- 2 | # generated by https://github.com/hashicorp/terraform-plugin-docs 3 | page_title: "zabbix_lld_snmp Resource - terraform-provider-zabbix" 4 | subcategory: "" 5 | description: |- 6 | 7 | --- 8 | 9 | # zabbix_lld_snmp (Resource) 10 | 11 | 12 | 13 | 14 | 15 | 16 | ## Schema 17 | 18 | ### Required 19 | 20 | - **hostid** (String) Host ID 21 | - **key** (String) LLD KEY 22 | - **name** (String) LLD Name 23 | - **snmp_oid** (String) SNMP OID 24 | 25 | ### Optional 26 | 27 | - **condition** (Block List) (see [below for nested schema](#nestedblock--condition)) 28 | - **delay** (String) LLD Delay period 29 | - **evaltype** (String) EvalType, one of: or, custom, andor, and 30 | - **formula** (String) Formula 31 | - **id** (String) The ID of this resource. 32 | - **interfaceid** (String) Host Interface ID 33 | - **lifetime** (String) LLD Stale Item Lifetime 34 | - **macro** (Block Set) (see [below for nested schema](#nestedblock--macro)) 35 | - **preprocessor** (Block List) (see [below for nested schema](#nestedblock--preprocessor)) 36 | - **snmp3_authpassphrase** (String) Authentication Passphrase (v3 only) 37 | - **snmp3_authprotocol** (String) Authentication Protocol (v3 only), one of: md5, sha 38 | - **snmp3_contextname** (String) Context Name (v3 only) 39 | - **snmp3_privpassphrase** (String) Priv Passphrase (v3 only) 40 | - **snmp3_privprotocol** (String) Priv Protocol (v3 only), one of: aes, des 41 | - **snmp3_securitylevel** (String) Security Level (v3 only), one of: noauthnopriv, authnopriv, authpriv 42 | - **snmp3_securityname** (String) Security Name (v3 only) 43 | - **snmp_community** (String) SNMP Community (v1/v2 only) 44 | - **snmp_version** (String) SNMP Version, one of: 1, 2, 3 45 | 46 | 47 | ### Nested Schema for `condition` 48 | 49 | Required: 50 | 51 | - **macro** (String) Filter Macro 52 | - **value** (String) Filter Value 53 | 54 | Optional: 55 | 56 | - **operator** (String) Operator, one of: match, notmatch 57 | 58 | Read-Only: 59 | 60 | - **id** (String) The ID of this resource. 61 | 62 | 63 | 64 | ### Nested Schema for `macro` 65 | 66 | Required: 67 | 68 | - **macro** (String) Macro 69 | - **path** (String) Macro Path 70 | 71 | 72 | 73 | ### Nested Schema for `preprocessor` 74 | 75 | Required: 76 | 77 | - **type** (String) Preprocessor type, zabbix identifier number 78 | 79 | Optional: 80 | 81 | - **error_handler** (String) 82 | - **error_handler_params** (String) 83 | - **params** (List of String) Preprocessor parameters 84 | 85 | Read-Only: 86 | 87 | - **id** (String) The ID of this resource. 88 | 89 | 90 | -------------------------------------------------------------------------------- /provider/resource_dependent_common.go: -------------------------------------------------------------------------------- 1 | package provider 2 | 3 | import ( 4 | "github.com/hashicorp/terraform-plugin-sdk/helper/schema" 5 | "github.com/hashicorp/terraform-plugin-sdk/helper/validation" 6 | "github.com/tpretz/go-zabbix-api" 7 | ) 8 | 9 | var schemaDependent = map[string]*schema.Schema{ 10 | "master_itemid": &schema.Schema{ 11 | Type: schema.TypeString, 12 | ValidateFunc: validation.StringIsNotWhiteSpace, 13 | Description: "Master Item ID", 14 | Required: true, 15 | }, 16 | } 17 | 18 | // resourceItemDependent terraform resource for agent items 19 | func resourceItemDependent() *schema.Resource { 20 | return &schema.Resource{ 21 | Create: itemGetCreateWrapper(itemDependentModFunc, itemDependentReadFunc), 22 | Read: itemGetReadWrapper(itemDependentReadFunc), 23 | Update: itemGetUpdateWrapper(itemDependentModFunc, itemDependentReadFunc), 24 | Delete: resourceItemDelete, 25 | Importer: &schema.ResourceImporter{ 26 | State: schema.ImportStatePassthrough, 27 | }, 28 | Schema: mergeSchemas(itemCommonSchema, schemaDependent), 29 | } 30 | } 31 | func resourceProtoItemDependent() *schema.Resource { 32 | return &schema.Resource{ 33 | Create: protoItemGetCreateWrapper(itemDependentModFunc, itemDependentReadFunc), 34 | Read: protoItemGetReadWrapper(itemDependentReadFunc), 35 | Update: protoItemGetUpdateWrapper(itemDependentModFunc, itemDependentReadFunc), 36 | Delete: resourceProtoItemDelete, 37 | Importer: &schema.ResourceImporter{ 38 | State: schema.ImportStatePassthrough, 39 | }, 40 | Schema: mergeSchemas(itemCommonSchema, itemPrototypeSchema, schemaDependent), 41 | } 42 | } 43 | func resourceLLDDependent() *schema.Resource { 44 | return &schema.Resource{ 45 | Create: lldGetCreateWrapper(lldDependentModFunc, lldDependentReadFunc), 46 | Read: lldGetReadWrapper(lldDependentReadFunc), 47 | Update: lldGetUpdateWrapper(lldDependentModFunc, lldDependentReadFunc), 48 | Delete: resourceLLDDelete, 49 | Importer: &schema.ResourceImporter{ 50 | State: schema.ImportStatePassthrough, 51 | }, 52 | Schema: mergeSchemas(lldCommonSchema, schemaDependent), 53 | } 54 | } 55 | 56 | func itemDependentModFunc(d *schema.ResourceData, m interface{}, item *zabbix.Item) { 57 | item.Type = zabbix.Dependent 58 | item.MasterItemID = d.Get("master_itemid").(string) 59 | } 60 | func lldDependentModFunc(d *schema.ResourceData, m interface{}, item *zabbix.LLDRule) { 61 | item.Type = zabbix.Dependent 62 | item.MasterItemID = d.Get("master_itemid").(string) 63 | } 64 | 65 | func itemDependentReadFunc(d *schema.ResourceData, m interface{}, item *zabbix.Item) { 66 | d.Set("master_itemid", item.MasterItemID) 67 | } 68 | func lldDependentReadFunc(d *schema.ResourceData, m interface{}, item *zabbix.LLDRule) { 69 | d.Set("master_itemid", item.MasterItemID) 70 | } 71 | -------------------------------------------------------------------------------- /docs/resources/lld_http.md: -------------------------------------------------------------------------------- 1 | --- 2 | # generated by https://github.com/hashicorp/terraform-plugin-docs 3 | page_title: "zabbix_lld_http Resource - terraform-provider-zabbix" 4 | subcategory: "" 5 | description: |- 6 | 7 | --- 8 | 9 | # zabbix_lld_http (Resource) 10 | 11 | 12 | 13 | 14 | 15 | 16 | ## Schema 17 | 18 | ### Required 19 | 20 | - **hostid** (String) Host ID 21 | - **key** (String) LLD KEY 22 | - **name** (String) LLD Name 23 | - **url** (String) url to probe 24 | 25 | ### Optional 26 | 27 | - **auth_type** (String) HTTP auth type, one of: basic, ntlm, kerberos, none 28 | - **condition** (Block List) (see [below for nested schema](#nestedblock--condition)) 29 | - **delay** (String) LLD Delay period 30 | - **evaltype** (String) EvalType, one of: or, custom, andor, and 31 | - **follow_redirects** (Boolean) follow http redirects 32 | - **formula** (String) Formula 33 | - **headers** (Map of String) 34 | - **id** (String) The ID of this resource. 35 | - **interfaceid** (String) Host Interface ID 36 | - **lifetime** (String) LLD Stale Item Lifetime 37 | - **macro** (Block Set) (see [below for nested schema](#nestedblock--macro)) 38 | - **password** (String, Sensitive) Authentication Password 39 | - **post_type** (String) HTTP post type, one of: xml, raw, json 40 | - **posts** (String) POST data to send in request 41 | - **preprocessor** (Block List) (see [below for nested schema](#nestedblock--preprocessor)) 42 | - **proxy** (String) HTTP proxy connection string 43 | - **request_method** (String) HTTP request method, one of: get, post, put, head 44 | - **retrieve_mode** (String) HTTP retrieve mode, one of: body, headers, both 45 | - **status_codes** (String) http status code 46 | - **timeout** (String) http request timeout 47 | - **username** (String) Authentication Username 48 | - **verify_host** (Boolean) https verify host 49 | - **verify_peer** (Boolean) https verify peer 50 | 51 | 52 | ### Nested Schema for `condition` 53 | 54 | Required: 55 | 56 | - **macro** (String) Filter Macro 57 | - **value** (String) Filter Value 58 | 59 | Optional: 60 | 61 | - **operator** (String) Operator, one of: match, notmatch 62 | 63 | Read-Only: 64 | 65 | - **id** (String) The ID of this resource. 66 | 67 | 68 | 69 | ### Nested Schema for `macro` 70 | 71 | Required: 72 | 73 | - **macro** (String) Macro 74 | - **path** (String) Macro Path 75 | 76 | 77 | 78 | ### Nested Schema for `preprocessor` 79 | 80 | Required: 81 | 82 | - **type** (String) Preprocessor type, zabbix identifier number 83 | 84 | Optional: 85 | 86 | - **error_handler** (String) 87 | - **error_handler_params** (String) 88 | - **params** (List of String) Preprocessor parameters 89 | 90 | Read-Only: 91 | 92 | - **id** (String) The ID of this resource. 93 | 94 | 95 | -------------------------------------------------------------------------------- /provider/resource_agent_common.go: -------------------------------------------------------------------------------- 1 | package provider 2 | 3 | import ( 4 | "github.com/hashicorp/terraform-plugin-sdk/helper/schema" 5 | "github.com/tpretz/go-zabbix-api" 6 | ) 7 | 8 | var schemaAgent = map[string]*schema.Schema{ 9 | "active": &schema.Schema{ 10 | Type: schema.TypeBool, 11 | Description: "Active zabbix agent Item", 12 | Optional: true, 13 | Default: false, 14 | }, 15 | } 16 | 17 | // resourceItemAgent terraform resource for agent items 18 | func resourceItemAgent() *schema.Resource { 19 | return &schema.Resource{ 20 | Create: itemGetCreateWrapper(itemAgentModFunc, itemAgentReadFunc), 21 | Read: itemGetReadWrapper(itemAgentReadFunc), 22 | Update: itemGetUpdateWrapper(itemAgentModFunc, itemAgentReadFunc), 23 | Delete: resourceItemDelete, 24 | Importer: &schema.ResourceImporter{ 25 | State: schema.ImportStatePassthrough, 26 | }, 27 | 28 | Schema: mergeSchemas(itemCommonSchema, itemDelaySchema, itemInterfaceSchema, schemaAgent), 29 | } 30 | } 31 | func resourceProtoItemAgent() *schema.Resource { 32 | return &schema.Resource{ 33 | Create: protoItemGetCreateWrapper(itemAgentModFunc, itemAgentReadFunc), 34 | Read: protoItemGetReadWrapper(itemAgentReadFunc), 35 | Update: protoItemGetUpdateWrapper(itemAgentModFunc, itemAgentReadFunc), 36 | Delete: resourceProtoItemDelete, 37 | Importer: &schema.ResourceImporter{ 38 | State: schema.ImportStatePassthrough, 39 | }, 40 | 41 | Schema: mergeSchemas(itemCommonSchema, itemDelaySchema, itemInterfaceSchema, itemPrototypeSchema, schemaAgent), 42 | } 43 | } 44 | func resourceLLDAgent() *schema.Resource { 45 | return &schema.Resource{ 46 | Create: lldGetCreateWrapper(lldAgentModFunc, lldAgentReadFunc), 47 | Read: lldGetReadWrapper(lldAgentReadFunc), 48 | Update: lldGetUpdateWrapper(lldAgentModFunc, lldAgentReadFunc), 49 | Delete: resourceLLDDelete, 50 | Importer: &schema.ResourceImporter{ 51 | State: schema.ImportStatePassthrough, 52 | }, 53 | 54 | Schema: mergeSchemas(lldCommonSchema, lldInterfaceSchema, schemaAgent), 55 | } 56 | } 57 | 58 | func itemAgentModFunc(d *schema.ResourceData, m interface{}, item *zabbix.Item) { 59 | t := zabbix.ZabbixAgent 60 | if d.Get("active").(bool) { 61 | t = zabbix.ZabbixAgentActive 62 | } 63 | item.Type = t 64 | item.InterfaceID = d.Get("interfaceid").(string) 65 | item.Delay = d.Get("delay").(string) 66 | } 67 | 68 | func lldAgentModFunc(d *schema.ResourceData, m interface{}, item *zabbix.LLDRule) { 69 | t := zabbix.ZabbixAgent 70 | if d.Get("active").(bool) { 71 | t = zabbix.ZabbixAgentActive 72 | } 73 | item.Type = t 74 | item.InterfaceID = d.Get("interfaceid").(string) 75 | } 76 | 77 | func itemAgentReadFunc(d *schema.ResourceData, m interface{}, item *zabbix.Item) { 78 | d.Set("interfaceid", item.InterfaceID) 79 | d.Set("delay", item.Delay) 80 | d.Set("active", item.Type == zabbix.ZabbixAgentActive) 81 | } 82 | 83 | func lldAgentReadFunc(d *schema.ResourceData, m interface{}, item *zabbix.LLDRule) { 84 | d.Set("interfaceid", item.InterfaceID) 85 | d.Set("active", item.Type == zabbix.ZabbixAgentActive) 86 | } 87 | -------------------------------------------------------------------------------- /provider/resource_hostgroup.go: -------------------------------------------------------------------------------- 1 | package provider 2 | 3 | import ( 4 | "errors" 5 | 6 | "github.com/hashicorp/terraform-plugin-sdk/helper/schema" 7 | "github.com/hashicorp/terraform-plugin-sdk/helper/validation" 8 | "github.com/tpretz/go-zabbix-api" 9 | ) 10 | 11 | // resourceHostgroup terraform resource handler 12 | func resourceHostgroup() *schema.Resource { 13 | return &schema.Resource{ 14 | Create: resourceHostgroupCreate, 15 | Read: resourceHostgroupRead, 16 | Update: resourceHostgroupUpdate, 17 | Delete: resourceHostgroupDelete, 18 | Importer: &schema.ResourceImporter{ 19 | State: schema.ImportStatePassthrough, 20 | }, 21 | 22 | Schema: map[string]*schema.Schema{ 23 | "name": &schema.Schema{ 24 | Type: schema.TypeString, 25 | ValidateFunc: validation.StringIsNotWhiteSpace, 26 | Description: "Hostgroup Name", 27 | Required: true, 28 | }, 29 | }, 30 | } 31 | } 32 | 33 | // dataHostgroup terraform data handler 34 | func dataHostgroup() *schema.Resource { 35 | return &schema.Resource{ 36 | Read: dataHostgroupRead, 37 | 38 | Schema: map[string]*schema.Schema{ 39 | "name": &schema.Schema{ 40 | Type: schema.TypeString, 41 | ValidateFunc: validation.StringIsNotWhiteSpace, 42 | Description: "Hostgroup Name", 43 | Required: true, 44 | }, 45 | }, 46 | } 47 | } 48 | 49 | // terraform hostgroup create function 50 | func resourceHostgroupCreate(d *schema.ResourceData, m interface{}) error { 51 | api := m.(*zabbix.API) 52 | 53 | item := zabbix.HostGroup{ 54 | Name: d.Get("name").(string), 55 | } 56 | 57 | items := []zabbix.HostGroup{item} 58 | 59 | err := api.HostGroupsCreate(items) 60 | 61 | if err != nil { 62 | return err 63 | } 64 | 65 | log.Trace("created hostgroup: %+v", items[0]) 66 | 67 | d.SetId(items[0].GroupID) 68 | 69 | return resourceHostgroupRead(d, m) 70 | } 71 | 72 | // hostgroupRead terraform hostgroup read function 73 | func hostgroupRead(d *schema.ResourceData, m interface{}, params zabbix.Params) error { 74 | api := m.(*zabbix.API) 75 | 76 | hostgroups, err := api.HostGroupsGet(params) 77 | 78 | if err != nil { 79 | return err 80 | } 81 | 82 | if len(hostgroups) < 1 { 83 | d.SetId("") 84 | return nil 85 | } 86 | if len(hostgroups) > 1 { 87 | return errors.New("multiple hostgroups found") 88 | } 89 | t := hostgroups[0] 90 | 91 | log.Debug("Got hostgroup: %+v", t) 92 | 93 | d.SetId(t.GroupID) 94 | d.Set("name", t.Name) 95 | 96 | return nil 97 | } 98 | 99 | // dataHostgroupRead terraform data resource read handler 100 | func dataHostgroupRead(d *schema.ResourceData, m interface{}) error { 101 | return hostgroupRead(d, m, zabbix.Params{ 102 | "filter": map[string]interface{}{ 103 | "name": d.Get("name"), 104 | }, 105 | }) 106 | } 107 | 108 | // resourceHostgroupRead terraform resource read handler 109 | func resourceHostgroupRead(d *schema.ResourceData, m interface{}) error { 110 | log.Debug("Lookup of hostgroup with id %s", d.Id()) 111 | 112 | return hostgroupRead(d, m, zabbix.Params{ 113 | "groupids": d.Id(), 114 | }) 115 | } 116 | 117 | // resourceHostgroupUpdate terraform resource update handler 118 | func resourceHostgroupUpdate(d *schema.ResourceData, m interface{}) error { 119 | api := m.(*zabbix.API) 120 | 121 | item := zabbix.HostGroup{ 122 | GroupID: d.Id(), 123 | Name: d.Get("name").(string), 124 | } 125 | 126 | items := []zabbix.HostGroup{item} 127 | 128 | err := api.HostGroupsUpdate(items) 129 | 130 | if err != nil { 131 | return err 132 | } 133 | 134 | return resourceHostgroupRead(d, m) 135 | } 136 | 137 | // resourceHostgroupDelete terraform resource delete handler 138 | func resourceHostgroupDelete(d *schema.ResourceData, m interface{}) error { 139 | api := m.(*zabbix.API) 140 | return api.HostGroupsDeleteByIds([]string{d.Id()}) 141 | } 142 | -------------------------------------------------------------------------------- /example.tf: -------------------------------------------------------------------------------- 1 | provider "zabbix" { 2 | username = "Admin" 3 | password = "zabbix" 4 | url = "http://127.0.0.1:8081/api_jsonrpc.php" 5 | } 6 | 7 | # data "zabbix_proxy" "a" { 8 | # host = "test" 9 | # } 10 | 11 | data "zabbix_host" "test" { 12 | host = "Zabbix server" 13 | } 14 | 15 | data "zabbix_hostgroup" "a" { 16 | name = "Hypervisors" 17 | } 18 | 19 | data "zabbix_template" "a" { 20 | host = "Template App FTP Service" 21 | } 22 | 23 | resource "zabbix_hostgroup" "a" { 24 | name = "test group" 25 | } 26 | 27 | resource "zabbix_item_internal" "a" { 28 | hostid = data.zabbix_host.test.id 29 | key = "zabbix[hosts]" 30 | name = "internal_test" 31 | valuetype = "float" 32 | } 33 | 34 | resource "zabbix_item_aggregate" "a" { 35 | hostid = data.zabbix_host.test.id 36 | key = "grpsum[\"${zabbix_hostgroup.a.name}\", \"test\", sum, 1h]" 37 | name = "test_aggregate" 38 | valuetype = "float" 39 | } 40 | 41 | resource "zabbix_item_snmp" "a" { 42 | hostid = zabbix_template.a.id 43 | key = "snmptesta" 44 | name = "snmp test a" 45 | valuetype = "float" 46 | snmp_version = 2 47 | snmp_oid = "DISMAN-EVENT-MIB::sysUpTimeInstance" 48 | } 49 | 50 | resource "zabbix_item_snmp" "b" { 51 | hostid = zabbix_template.a.id 52 | key = "snmptestb" 53 | name = "snmp test b" 54 | valuetype = "float" 55 | snmp_version = 3 56 | snmp_oid = "DISMAN-EVENT-MIB::sysUpTimeInstance" 57 | } 58 | 59 | resource "zabbix_item_simple" "ping" { 60 | hostid = zabbix_template.a.id 61 | key = "icmpping[,,,,]" 62 | name = "Ping" 63 | valuetype = "float" 64 | } 65 | 66 | resource "zabbix_item_agent" "a" { 67 | hostid = zabbix_template.a.id 68 | key = "agent.hostname" 69 | name = "Hostname" 70 | valuetype = "text" 71 | } 72 | 73 | resource "zabbix_item_dependent" "a" { 74 | master_itemid = zabbix_item_agent.a.id 75 | hostid = zabbix_template.a.id 76 | key = "custom.abc" 77 | name = "Hostname abc" 78 | valuetype = "text" 79 | } 80 | 81 | resource "zabbix_item_agent" "b" { 82 | hostid = zabbix_template.a.id 83 | key = "agent.version" 84 | name = "Hostname(b)" 85 | valuetype = "text" 86 | 87 | active = true 88 | } 89 | 90 | resource "zabbix_trigger" "ping" { 91 | name = "Ping" 92 | expression = "{${zabbix_template.a.host}:${zabbix_item_simple.ping.key}.last()}=1" 93 | } 94 | 95 | resource "zabbix_item_trapper" "a" { 96 | hostid = data.zabbix_host.test.id 97 | key = "abc_def" 98 | name = "ABC DEF" 99 | valuetype = "float" 100 | } 101 | 102 | resource "zabbix_item_http" "a" { 103 | hostid = zabbix_host.a.id 104 | key = "http_one" 105 | name = "http one" 106 | valuetype = "text" 107 | 108 | url = "http://google.com" 109 | interfaceid = zabbix_host.a.interface[0].id 110 | verify_host = true 111 | 112 | preprocessor { 113 | type = "5" 114 | params = ["^test$","bob"] 115 | } 116 | } 117 | 118 | resource "zabbix_trigger" "b" { 119 | name = "test trigger" 120 | expression = "{${data.zabbix_host.test.host}:${zabbix_item_trapper.a.key}.nodata(120)}=1" 121 | priority = "high" 122 | dependencies = [zabbix_trigger.c.id] 123 | } 124 | resource "zabbix_trigger" "c" { 125 | name = "test trigger" 126 | expression = "{${data.zabbix_host.test.host}:${zabbix_item_trapper.a.key}.nodata(240)}=1" 127 | 128 | 129 | tag { 130 | key = "cheese" 131 | value = "chedder" 132 | } 133 | tag { 134 | key = "bob" 135 | } 136 | tag { 137 | key = "category" 138 | value = "spec1al" 139 | } 140 | } 141 | 142 | resource "zabbix_template" "a" { 143 | groups = [zabbix_hostgroup.a.id] 144 | host = "example template" 145 | name = "visible name" 146 | 147 | macro { 148 | name = "{$SOMETHING}" 149 | value = "GOOD" 150 | } 151 | } 152 | 153 | resource "zabbix_host" "a" { 154 | host = "host.example.com" 155 | groups = [zabbix_hostgroup.a.id, data.zabbix_hostgroup.a.id] 156 | templates = [zabbix_template.a.id, data.zabbix_template.a.id] 157 | #proxyid = data.zabbix_proxy.a.id 158 | 159 | interface { 160 | dns = "eth0.host.example.com" 161 | type = "snmp" 162 | port = 1161 163 | } 164 | interface { 165 | dns = "eth0.host.example.com" 166 | main = true 167 | } 168 | 169 | macro { 170 | name = "{$SOMETHING}" 171 | value = "ELSE" 172 | } 173 | } 174 | -------------------------------------------------------------------------------- /provider/resource_application.go: -------------------------------------------------------------------------------- 1 | package provider 2 | 3 | import ( 4 | "errors" 5 | 6 | "github.com/hashicorp/terraform-plugin-sdk/helper/schema" 7 | "github.com/hashicorp/terraform-plugin-sdk/helper/validation" 8 | "github.com/tpretz/go-zabbix-api" 9 | ) 10 | 11 | // resourceApplication terraform resource handler 12 | func resourceApplication() *schema.Resource { 13 | return &schema.Resource{ 14 | Create: resourceApplicationCreate, 15 | Read: resourceApplicationRead, 16 | Delete: resourceApplicationDelete, 17 | Importer: &schema.ResourceImporter{ 18 | State: schema.ImportStatePassthrough, 19 | }, 20 | 21 | Schema: map[string]*schema.Schema{ 22 | "name": &schema.Schema{ 23 | Type: schema.TypeString, 24 | ValidateFunc: validation.StringIsNotWhiteSpace, 25 | ForceNew: true, 26 | Description: "Application Name", 27 | Required: true, 28 | }, 29 | "hostid": &schema.Schema{ 30 | Type: schema.TypeString, 31 | ValidateFunc: validation.StringIsNotWhiteSpace, 32 | ForceNew: true, 33 | Description: "Host ID", 34 | Required: true, 35 | }, 36 | }, 37 | } 38 | } 39 | 40 | // dataApplication terraform data handler 41 | func dataApplication() *schema.Resource { 42 | return &schema.Resource{ 43 | Read: dataApplicationRead, 44 | 45 | Schema: map[string]*schema.Schema{ 46 | "name": &schema.Schema{ 47 | Type: schema.TypeString, 48 | ValidateFunc: validation.StringIsNotWhiteSpace, 49 | Description: "Application Name", 50 | Required: true, 51 | }, 52 | "hostid": &schema.Schema{ 53 | Type: schema.TypeString, 54 | ValidateFunc: validation.StringIsNotWhiteSpace, 55 | Description: "Host ID", 56 | Optional: true, 57 | }, 58 | }, 59 | } 60 | } 61 | 62 | // terraform Application create function 63 | func resourceApplicationCreate(d *schema.ResourceData, m interface{}) error { 64 | api := m.(*zabbix.API) 65 | 66 | item := zabbix.Application{ 67 | Name: d.Get("name").(string), 68 | HostID: d.Get("hostid").(string), 69 | } 70 | 71 | items := []zabbix.Application{item} 72 | 73 | err := api.ApplicationsCreate(items) 74 | 75 | if err != nil { 76 | return err 77 | } 78 | 79 | log.Trace("created Application: %+v", items[0]) 80 | 81 | d.SetId(items[0].ApplicationID) 82 | 83 | return resourceApplicationRead(d, m) 84 | } 85 | 86 | // ApplicationRead terraform Application read function 87 | func ApplicationRead(d *schema.ResourceData, m interface{}, params zabbix.Params) error { 88 | api := m.(*zabbix.API) 89 | 90 | if api.Config.Version >= 50400 { 91 | return errors.New("application API no longer supported in zabbix versions >= 5.4, see documentation around the use of tags to replace its behaviour") 92 | } 93 | 94 | Applications, err := api.ApplicationsGet(params) 95 | 96 | if err != nil { 97 | return err 98 | } 99 | 100 | if len(Applications) < 1 { 101 | d.SetId("") 102 | return nil 103 | } 104 | if len(Applications) > 1 { 105 | return errors.New("multiple Applications found") 106 | } 107 | t := Applications[0] 108 | 109 | log.Debug("Got Application: %+v", t) 110 | 111 | d.SetId(t.ApplicationID) 112 | d.Set("name", t.Name) 113 | d.Set("hostid", t.HostID) 114 | 115 | return nil 116 | } 117 | 118 | // dataApplicationRead terraform data resource read handler 119 | func dataApplicationRead(d *schema.ResourceData, m interface{}) error { 120 | params := zabbix.Params{ 121 | "filter": map[string]interface{}{ 122 | "name": d.Get("name"), 123 | }, 124 | } 125 | 126 | if v, ok := d.GetOk("hostid"); ok { 127 | params["filter"].(map[string]interface{})["hostid"] = v 128 | } 129 | return ApplicationRead(d, m, params) 130 | } 131 | 132 | // resourceApplicationRead terraform resource read handler 133 | func resourceApplicationRead(d *schema.ResourceData, m interface{}) error { 134 | log.Debug("Lookup of Application with id %s", d.Id()) 135 | 136 | return ApplicationRead(d, m, zabbix.Params{ 137 | "applicationids": d.Id(), 138 | }) 139 | } 140 | 141 | // resourceApplicationDelete terraform resource delete handler 142 | func resourceApplicationDelete(d *schema.ResourceData, m interface{}) error { 143 | api := m.(*zabbix.API) 144 | return api.ApplicationsDeleteByIds([]string{d.Id()}) 145 | } 146 | -------------------------------------------------------------------------------- /docs/data-sources/host.md: -------------------------------------------------------------------------------- 1 | --- 2 | # generated by https://github.com/hashicorp/terraform-plugin-docs 3 | page_title: "zabbix_host Data Source - terraform-provider-zabbix" 4 | subcategory: "" 5 | description: |- 6 | 7 | --- 8 | 9 | # zabbix_host (Data Source) 10 | 11 | 12 | 13 | 14 | 15 | 16 | ## Schema 17 | 18 | ### Optional 19 | 20 | - **enabled** (Boolean) Enable host for monitoring 21 | - **host** (String) FQDN of host 22 | - **hostid** (String) 23 | - **id** (String) The ID of this resource. 24 | - **inventory_mode** (String) Inventory Mode, one of: disabled, manual, automatic 25 | - **macro** (Block List) (see [below for nested schema](#nestedblock--macro)) 26 | - **name** (String) Zabbix host displayname, defaults to the value of "host" 27 | - **tag** (Block Set) (see [below for nested schema](#nestedblock--tag)) 28 | - **templates** (Set of String) Template IDs to attach to this host 29 | 30 | ### Read-Only 31 | 32 | - **groups** (Set of String) Hostgroup IDs to associate this host with 33 | - **interface** (List of Object) Host interfaces (see [below for nested schema](#nestedatt--interface)) 34 | - **inventory** (List of Object) (see [below for nested schema](#nestedatt--inventory)) 35 | - **proxyid** (String) ID of proxy to monitor this host 36 | 37 | 38 | ### Nested Schema for `macro` 39 | 40 | Required: 41 | 42 | - **name** (String) Macro Name (key) 43 | - **value** (String) Macro Value 44 | 45 | Read-Only: 46 | 47 | - **id** (String) The ID of this resource. 48 | 49 | 50 | 51 | ### Nested Schema for `tag` 52 | 53 | Required: 54 | 55 | - **key** (String) Tag Key 56 | 57 | Optional: 58 | 59 | - **value** (String) Tag Value 60 | 61 | 62 | 63 | ### Nested Schema for `interface` 64 | 65 | Read-Only: 66 | 67 | - **dns** (String) 68 | - **id** (String) 69 | - **ip** (String) 70 | - **main** (Boolean) 71 | - **port** (Number) 72 | - **snmp3_authpassphrase** (String) 73 | - **snmp3_authprotocol** (String) 74 | - **snmp3_contextname** (String) 75 | - **snmp3_privpassphrase** (String) 76 | - **snmp3_privprotocol** (String) 77 | - **snmp3_securitylevel** (String) 78 | - **snmp3_securityname** (String) 79 | - **snmp_bulk** (Boolean) 80 | - **snmp_community** (String) 81 | - **snmp_version** (String) 82 | - **type** (String) 83 | 84 | 85 | 86 | ### Nested Schema for `inventory` 87 | 88 | Read-Only: 89 | 90 | - **alias** (String) 91 | - **asset_tag** (String) 92 | - **chassis** (String) 93 | - **contact** (String) 94 | - **contract_number** (String) 95 | - **date_hw_decomm** (String) 96 | - **date_hw_expiry** (String) 97 | - **date_hw_install** (String) 98 | - **date_hw_purchase** (String) 99 | - **deployment_status** (String) 100 | - **hardware** (String) 101 | - **hardware_full** (String) 102 | - **host_netmask** (String) 103 | - **host_networks** (String) 104 | - **host_router** (String) 105 | - **hw_arch** (String) 106 | - **installer_name** (String) 107 | - **location** (String) 108 | - **location_lat** (String) 109 | - **location_lon** (String) 110 | - **macaddress_a** (String) 111 | - **macaddress_b** (String) 112 | - **model** (String) 113 | - **name** (String) 114 | - **notes** (String) 115 | - **oob_ip** (String) 116 | - **oob_netmask** (String) 117 | - **oob_router** (String) 118 | - **os** (String) 119 | - **os_full** (String) 120 | - **os_short** (String) 121 | - **poc_1_cell** (String) 122 | - **poc_1_email** (String) 123 | - **poc_1_name** (String) 124 | - **poc_1_notes** (String) 125 | - **poc_1_phone_a** (String) 126 | - **poc_1_phone_b** (String) 127 | - **poc_1_screen** (String) 128 | - **poc_2_cell** (String) 129 | - **poc_2_email** (String) 130 | - **poc_2_name** (String) 131 | - **poc_2_notes** (String) 132 | - **poc_2_phone_a** (String) 133 | - **poc_2_phone_b** (String) 134 | - **poc_2_screen** (String) 135 | - **serialno_a** (String) 136 | - **serialno_b** (String) 137 | - **site_address_a** (String) 138 | - **site_address_b** (String) 139 | - **site_address_c** (String) 140 | - **site_city** (String) 141 | - **site_country** (String) 142 | - **site_notes** (String) 143 | - **site_rack** (String) 144 | - **site_state** (String) 145 | - **site_zip** (String) 146 | - **software** (String) 147 | - **software_app_a** (String) 148 | - **software_app_b** (String) 149 | - **software_app_c** (String) 150 | - **software_app_d** (String) 151 | - **software_app_e** (String) 152 | - **software_full** (String) 153 | - **tag** (String) 154 | - **type** (String) 155 | - **type_full** (String) 156 | - **url_a** (String) 157 | - **url_b** (String) 158 | - **url_c** (String) 159 | - **vendor** (String) 160 | 161 | 162 | -------------------------------------------------------------------------------- /docker/docker-compose.yml: -------------------------------------------------------------------------------- 1 | version: '3.5' 2 | services: 3 | zabbix-server: 4 | image: zabbix/zabbix-server-mysql:ubuntu-4.0-latest 5 | ports: 6 | - "10051:10051" 7 | volumes: 8 | - ./zbx_env/usr/lib/zabbix/alertscripts:/usr/lib/zabbix/alertscripts:ro 9 | - ./zbx_env/usr/lib/zabbix/externalscripts:/usr/lib/zabbix/externalscripts:ro 10 | - ./zbx_env/var/lib/zabbix/modules:/var/lib/zabbix/modules:ro 11 | - ./zbx_env/var/lib/zabbix/enc:/var/lib/zabbix/enc:ro 12 | - ./zbx_env/var/lib/zabbix/ssh_keys:/var/lib/zabbix/ssh_keys:ro 13 | - ./zbx_env/var/lib/zabbix/mibs:/var/lib/zabbix/mibs:ro 14 | - ./zbx_env/var/lib/zabbix/snmptraps:/var/lib/zabbix/snmptraps:ro 15 | links: 16 | - mysql-server:mysql-server 17 | ulimits: 18 | nproc: 65535 19 | nofile: 20 | soft: 20000 21 | hard: 40000 22 | deploy: 23 | resources: 24 | limits: 25 | cpus: '0.70' 26 | memory: 1G 27 | reservations: 28 | cpus: '0.5' 29 | memory: 512M 30 | env_file: 31 | - .env_db_mysql 32 | - .env_srv 33 | secrets: 34 | - MYSQL_USER 35 | - MYSQL_PASSWORD 36 | - MYSQL_ROOT_PASSWORD 37 | user: root 38 | depends_on: 39 | - mysql-server 40 | networks: 41 | zbx_net_backend: 42 | aliases: 43 | - zabbix-server 44 | - zabbix-server-mysql 45 | - zabbix-server-ubuntu-mysql 46 | - zabbix-server-mysql-ubuntu 47 | zbx_net_frontend: 48 | # devices: 49 | # - "/dev/ttyUSB0:/dev/ttyUSB0" 50 | stop_grace_period: 30s 51 | sysctls: 52 | - net.ipv4.ip_local_port_range=1024 65000 53 | - net.ipv4.conf.all.accept_redirects=0 54 | - net.ipv4.conf.all.secure_redirects=0 55 | - net.ipv4.conf.all.send_redirects=0 56 | labels: 57 | com.zabbix.description: "Zabbix server with MySQL database support" 58 | com.zabbix.company: "Zabbix SIA" 59 | com.zabbix.component: "zabbix-server" 60 | com.zabbix.dbtype: "mysql" 61 | com.zabbix.os: "ubuntu" 62 | zabbix-web-nginx-mysql: 63 | image: zabbix/zabbix-web-nginx-mysql:ubuntu-4.0-latest 64 | ports: 65 | - "8081:80" 66 | - "8443:443" 67 | links: 68 | - mysql-server:mysql-server 69 | - zabbix-server:zabbix-server 70 | volumes: 71 | - ./zbx_env/etc/ssl/nginx:/etc/ssl/nginx:ro 72 | deploy: 73 | resources: 74 | limits: 75 | cpus: '0.70' 76 | memory: 512M 77 | reservations: 78 | cpus: '0.5' 79 | memory: 256M 80 | env_file: 81 | - .env_db_mysql 82 | - .env_web 83 | secrets: 84 | - MYSQL_USER 85 | - MYSQL_PASSWORD 86 | user: root 87 | depends_on: 88 | - mysql-server 89 | - zabbix-server 90 | healthcheck: 91 | test: ["CMD", "curl", "-f", "http://localhost"] 92 | interval: 10s 93 | timeout: 5s 94 | retries: 3 95 | start_period: 30s 96 | networks: 97 | zbx_net_backend: 98 | aliases: 99 | - zabbix-web-nginx-mysql 100 | - zabbix-web-nginx-ubuntu-mysql 101 | - zabbix-web-nginx-mysql-ubuntu 102 | zbx_net_frontend: 103 | stop_grace_period: 10s 104 | sysctls: 105 | - net.core.somaxconn=65535 106 | labels: 107 | com.zabbix.description: "Zabbix frontend on Nginx web-server with MySQL database support" 108 | com.zabbix.company: "Zabbix SIA" 109 | com.zabbix.component: "zabbix-frontend" 110 | com.zabbix.webserver: "nginx" 111 | com.zabbix.dbtype: "mysql" 112 | com.zabbix.os: "ubuntu" 113 | mysql-server: 114 | image: mysql:8.0 115 | command: [mysqld, --character-set-server=utf8, --collation-server=utf8_bin, --default-authentication-plugin=mysql_native_password] 116 | volumes: 117 | - ./zbx_env/var/lib/mysql:/var/lib/mysql:rw 118 | env_file: 119 | - .env_db_mysql 120 | secrets: 121 | - MYSQL_USER 122 | - MYSQL_PASSWORD 123 | - MYSQL_ROOT_PASSWORD 124 | user: root 125 | stop_grace_period: 1m 126 | networks: 127 | zbx_net_backend: 128 | aliases: 129 | - mysql-server 130 | - zabbix-database 131 | - mysql-database 132 | 133 | db_data_mysql: 134 | image: busybox 135 | volumes: 136 | - ./zbx_env/var/lib/mysql:/var/lib/mysql:rw 137 | networks: 138 | zbx_net_frontend: 139 | driver: bridge 140 | driver_opts: 141 | com.docker.network.enable_ipv6: "false" 142 | ipam: 143 | driver: default 144 | config: 145 | - subnet: 172.16.238.0/24 146 | zbx_net_backend: 147 | driver: bridge 148 | driver_opts: 149 | com.docker.network.enable_ipv6: "false" 150 | internal: true 151 | ipam: 152 | driver: default 153 | config: 154 | - subnet: 172.16.239.0/24 155 | 156 | secrets: 157 | MYSQL_USER: 158 | file: ./.MYSQL_USER 159 | MYSQL_PASSWORD: 160 | file: ./.MYSQL_PASSWORD 161 | MYSQL_ROOT_PASSWORD: 162 | file: ./.MYSQL_ROOT_PASSWORD 163 | -------------------------------------------------------------------------------- /provider/provider.go: -------------------------------------------------------------------------------- 1 | package provider 2 | 3 | import ( 4 | logger "log" 5 | 6 | "github.com/hashicorp/terraform-plugin-sdk/helper/schema" 7 | "github.com/hashicorp/terraform-plugin-sdk/helper/validation" 8 | "github.com/hashicorp/terraform/helper/hashcode" 9 | "github.com/tpretz/go-zabbix-api" 10 | ) 11 | 12 | // Provider definition 13 | func Provider() *schema.Provider { 14 | return &schema.Provider{ 15 | Schema: map[string]*schema.Schema{ 16 | "username": &schema.Schema{ 17 | Type: schema.TypeString, 18 | Required: true, 19 | Description: "Zabbix API username", 20 | ValidateFunc: validation.StringIsNotWhiteSpace, 21 | DefaultFunc: schema.MultiEnvDefaultFunc([]string{"ZABBIX_USER", "ZABBIX_USERNAME"}, nil), 22 | }, 23 | "password": &schema.Schema{ 24 | Type: schema.TypeString, 25 | Required: true, 26 | Description: "Zabbix API password", 27 | ValidateFunc: validation.StringIsNotWhiteSpace, 28 | DefaultFunc: schema.MultiEnvDefaultFunc([]string{"ZABBIX_PASS", "ZABBIX_PASSWORD"}, nil), 29 | }, 30 | "url": &schema.Schema{ 31 | Type: schema.TypeString, 32 | Required: true, 33 | Description: "Zabbix API url", 34 | DefaultFunc: schema.MultiEnvDefaultFunc([]string{"ZABBIX_URL", "ZABBIX_SERVER_URL"}, nil), 35 | ValidateFunc: validation.IsURLWithHTTPorHTTPS, 36 | }, 37 | "tls_insecure": &schema.Schema{ 38 | Type: schema.TypeBool, 39 | Description: "Disable TLS certificate checking (for testing use only)", 40 | Optional: true, 41 | Default: false, 42 | }, 43 | "serialize": &schema.Schema{ 44 | Type: schema.TypeBool, 45 | Optional: true, 46 | Default: false, 47 | Description: "Serialize API requests, if required due to API race conditions", 48 | }, 49 | }, 50 | DataSourcesMap: map[string]*schema.Resource{ 51 | "zabbix_host": dataHost(), 52 | "zabbix_application": dataApplication(), 53 | "zabbix_proxy": dataProxy(), 54 | "zabbix_hostgroup": dataHostgroup(), 55 | "zabbix_template": dataTemplate(), 56 | }, 57 | ResourcesMap: map[string]*schema.Resource{ 58 | "zabbix_trigger": resourceTrigger(), 59 | "zabbix_proto_trigger": resourceProtoTrigger(), 60 | "zabbix_template": resourceTemplate(), 61 | "zabbix_hostgroup": resourceHostgroup(), 62 | "zabbix_host": resourceHost(), 63 | "zabbix_application": resourceApplication(), 64 | 65 | "zabbix_graph": resourceGraph(), 66 | "zabbix_proto_graph": resourceProtoGraph(), 67 | 68 | "zabbix_item_trapper": resourceItemTrapper(), 69 | "zabbix_proto_item_trapper": resourceProtoItemTrapper(), 70 | "zabbix_lld_trapper": resourceLLDTrapper(), 71 | 72 | "zabbix_item_http": resourceItemHttp(), 73 | "zabbix_proto_item_http": resourceProtoItemHttp(), 74 | "zabbix_lld_http": resourceLLDHttp(), 75 | 76 | "zabbix_item_simple": resourceItemSimple(), 77 | "zabbix_proto_item_simple": resourceProtoItemSimple(), 78 | "zabbix_lld_simple": resourceLLDSimple(), 79 | 80 | "zabbix_item_external": resourceItemExternal(), 81 | "zabbix_proto_item_external": resourceProtoItemExternal(), 82 | "zabbix_lld_external": resourceLLDExternal(), 83 | 84 | "zabbix_item_internal": resourceItemInternal(), 85 | "zabbix_proto_item_internal": resourceProtoItemInternal(), 86 | "zabbix_lld_internal": resourceLLDInternal(), 87 | 88 | "zabbix_item_snmp": resourceItemSnmp(), 89 | "zabbix_proto_item_snmp": resourceProtoItemSnmp(), 90 | "zabbix_lld_snmp": resourceLLDSnmp(), 91 | 92 | "zabbix_item_snmptrap": resourceItemSnmpTrap(), 93 | "zabbix_proto_item_snmptrap": resourceProtoItemSnmpTrap(), 94 | 95 | "zabbix_item_agent": resourceItemAgent(), 96 | "zabbix_proto_item_agent": resourceProtoItemAgent(), 97 | "zabbix_lld_agent": resourceLLDAgent(), 98 | 99 | "zabbix_item_aggregate": resourceItemAggregate(), 100 | "zabbix_proto_item_aggregate": resourceProtoItemAggregate(), 101 | 102 | "zabbix_item_calculated": resourceItemCalculated(), 103 | "zabbix_proto_item_calculated": resourceProtoItemCalculated(), 104 | 105 | "zabbix_item_dependent": resourceItemDependent(), 106 | "zabbix_proto_item_dependent": resourceProtoItemDependent(), 107 | "zabbix_lld_dependent": resourceLLDDependent(), 108 | }, 109 | ConfigureFunc: providerConfigure, 110 | } 111 | } 112 | 113 | // providerConfigure configure this provider 114 | func providerConfigure(d *schema.ResourceData) (meta interface{}, err error) { 115 | log.Trace("Started zabbix provider init") 116 | l := logger.New(stderr, "[DEBUG] ", logger.LstdFlags) 117 | 118 | api, apierr := zabbix.NewAPI(zabbix.Config{ 119 | Url: d.Get("url").(string), 120 | TlsNoVerify: d.Get("tls_insecure").(bool), 121 | Log: l, 122 | Serialize: d.Get("serialize").(bool), 123 | }) 124 | if apierr != nil { 125 | return nil, apierr 126 | } 127 | 128 | _, err = api.Login(d.Get("username").(string), d.Get("password").(string)) 129 | meta = api 130 | log.Trace("Started zabbix provider got error: %+v", err) 131 | 132 | return 133 | } 134 | 135 | // tagGenerate build tag structs from terraform inputs 136 | func tagGenerate(d *schema.ResourceData) (tags zabbix.Tags) { 137 | set := d.Get("tag").(*schema.Set).List() 138 | tags = make(zabbix.Tags, len(set)) 139 | 140 | for i := 0; i < len(set); i++ { 141 | current := set[i].(map[string]interface{}) 142 | tags[i] = zabbix.Tag{ 143 | Tag: current["key"].(string), 144 | Value: current["value"].(string), 145 | } 146 | } 147 | 148 | return 149 | } 150 | 151 | // flattenTags convert response to terraform input 152 | func flattenTags(list zabbix.Tags) *schema.Set { 153 | set := schema.NewSet(func(i interface{}) int { 154 | m := i.(map[string]interface{}) 155 | return hashcode.String(m["key"].(string) + "V" + m["value"].(string)) 156 | }, []interface{}{}) 157 | for i := 0; i < len(list); i++ { 158 | set.Add(map[string]interface{}{ 159 | "key": list[i].Tag, 160 | "value": list[i].Value, 161 | }) 162 | } 163 | return set 164 | } 165 | -------------------------------------------------------------------------------- /docs/resources/host.md: -------------------------------------------------------------------------------- 1 | --- 2 | # generated by https://github.com/hashicorp/terraform-plugin-docs 3 | page_title: "zabbix_host Resource - terraform-provider-zabbix" 4 | subcategory: "" 5 | description: |- 6 | 7 | --- 8 | 9 | # zabbix_host (Resource) 10 | 11 | 12 | 13 | 14 | 15 | 16 | ## Schema 17 | 18 | ### Required 19 | 20 | - **groups** (Set of String) Hostgroup IDs to associate this host with 21 | - **host** (String) FQDN of host 22 | - **interface** (Block List, Min: 1) (see [below for nested schema](#nestedblock--interface)) 23 | 24 | ### Optional 25 | 26 | - **enabled** (Boolean) Enable host for monitoring 27 | - **id** (String) The ID of this resource. 28 | - **inventory** (Block List) (see [below for nested schema](#nestedblock--inventory)) 29 | - **inventory_mode** (String) Inventory Mode, one of: disabled, manual, automatic 30 | - **macro** (Block List) (see [below for nested schema](#nestedblock--macro)) 31 | - **name** (String) Zabbix host displayname, defaults to the value of "host" 32 | - **proxyid** (String) ID of proxy to monitor this host 33 | - **tag** (Block Set) (see [below for nested schema](#nestedblock--tag)) 34 | - **templates** (Set of String) Template IDs to attach to this host 35 | 36 | 37 | ### Nested Schema for `interface` 38 | 39 | Optional: 40 | 41 | - **dns** (String) Interface DNS name 42 | - **ip** (String) Interface IP address 43 | - **main** (Boolean) Primary interface of this type 44 | - **port** (Number) Destination Port 45 | - **snmp3_authpassphrase** (String) Authentication Passphrase (v3 only) 46 | - **snmp3_authprotocol** (String) Authentication Protocol (v3 only), one of: md5, sha 47 | - **snmp3_contextname** (String) Context Name (v3 only) 48 | - **snmp3_privpassphrase** (String) Priv Passphrase (v3 only) 49 | - **snmp3_privprotocol** (String) Priv Protocol (v3 only), one of: des, aes 50 | - **snmp3_securitylevel** (String) Security Level (v3 only), one of: noauthnopriv, authnopriv, authpriv 51 | - **snmp3_securityname** (String) Security Name (v3 only) 52 | - **snmp_bulk** (Boolean) SNMP Bulk 53 | - **snmp_community** (String) HSNMP Community (v1/v2 only) 54 | - **snmp_version** (String) SNMP Version, one of: 1, 2, 3 55 | - **type** (String) Interface type 56 | 57 | Read-Only: 58 | 59 | - **id** (String) Interface ID (internally generated) 60 | 61 | 62 | 63 | ### Nested Schema for `inventory` 64 | 65 | Optional: 66 | 67 | - **alias** (String) Inventory alias 68 | - **asset_tag** (String) Inventory asset_tag 69 | - **chassis** (String) Inventory chassis 70 | - **contact** (String) Inventory contact 71 | - **contract_number** (String) Inventory contract_number 72 | - **date_hw_decomm** (String) Inventory date_hw_decomm 73 | - **date_hw_expiry** (String) Inventory date_hw_expiry 74 | - **date_hw_install** (String) Inventory date_hw_install 75 | - **date_hw_purchase** (String) Inventory date_hw_purchase 76 | - **deployment_status** (String) Inventory deployment_status 77 | - **hardware** (String) Inventory hardware 78 | - **hardware_full** (String) Inventory hardware_full 79 | - **host_netmask** (String) Inventory host_netmask 80 | - **host_networks** (String) Inventory host_networks 81 | - **host_router** (String) Inventory host_router 82 | - **hw_arch** (String) Inventory hw_arch 83 | - **installer_name** (String) Inventory installer_name 84 | - **location** (String) Inventory location 85 | - **location_lat** (String) Inventory location_lat 86 | - **location_lon** (String) Inventory location_lon 87 | - **macaddress_a** (String) Inventory macaddress_a 88 | - **macaddress_b** (String) Inventory macaddress_b 89 | - **model** (String) Inventory model 90 | - **name** (String) Inventory name 91 | - **notes** (String) Inventory notes 92 | - **oob_ip** (String) Inventory oob_ip 93 | - **oob_netmask** (String) Inventory oob_netmask 94 | - **oob_router** (String) Inventory oob_router 95 | - **os** (String) Inventory os 96 | - **os_full** (String) Inventory os_full 97 | - **os_short** (String) Inventory os_short 98 | - **poc_1_cell** (String) Inventory poc_1_cell 99 | - **poc_1_email** (String) Inventory poc_1_email 100 | - **poc_1_name** (String) Inventory poc_1_name 101 | - **poc_1_notes** (String) Inventory poc_1_notes 102 | - **poc_1_phone_a** (String) Inventory poc_1_phone_a 103 | - **poc_1_phone_b** (String) Inventory poc_1_phone_b 104 | - **poc_1_screen** (String) Inventory poc_1_screen 105 | - **poc_2_cell** (String) Inventory poc_2_cell 106 | - **poc_2_email** (String) Inventory poc_2_email 107 | - **poc_2_name** (String) Inventory poc_2_name 108 | - **poc_2_notes** (String) Inventory poc_2_notes 109 | - **poc_2_phone_a** (String) Inventory poc_2_phone_a 110 | - **poc_2_phone_b** (String) Inventory poc_2_phone_b 111 | - **poc_2_screen** (String) Inventory poc_2_screen 112 | - **serialno_a** (String) Inventory serialno_a 113 | - **serialno_b** (String) Inventory serialno_b 114 | - **site_address_a** (String) Inventory site_address_a 115 | - **site_address_b** (String) Inventory site_address_b 116 | - **site_address_c** (String) Inventory site_address_c 117 | - **site_city** (String) Inventory site_city 118 | - **site_country** (String) Inventory site_country 119 | - **site_notes** (String) Inventory site_notes 120 | - **site_rack** (String) Inventory site_rack 121 | - **site_state** (String) Inventory site_state 122 | - **site_zip** (String) Inventory site_zip 123 | - **software** (String) Inventory software 124 | - **software_app_a** (String) Inventory software_app_a 125 | - **software_app_b** (String) Inventory software_app_b 126 | - **software_app_c** (String) Inventory software_app_c 127 | - **software_app_d** (String) Inventory software_app_d 128 | - **software_app_e** (String) Inventory software_app_e 129 | - **software_full** (String) Inventory software_full 130 | - **tag** (String) Inventory tag 131 | - **type** (String) Inventory type 132 | - **type_full** (String) Inventory type_full 133 | - **url_a** (String) Inventory url_a 134 | - **url_b** (String) Inventory url_b 135 | - **url_c** (String) Inventory url_c 136 | - **vendor** (String) Inventory vendor 137 | 138 | 139 | 140 | ### Nested Schema for `macro` 141 | 142 | Required: 143 | 144 | - **name** (String) Macro Name (key) 145 | - **value** (String) Macro Value 146 | 147 | Read-Only: 148 | 149 | - **id** (String) The ID of this resource. 150 | 151 | 152 | 153 | ### Nested Schema for `tag` 154 | 155 | Required: 156 | 157 | - **key** (String) Tag Key 158 | 159 | Optional: 160 | 161 | - **value** (String) Tag Value 162 | 163 | 164 | -------------------------------------------------------------------------------- /provider/resource_template.go: -------------------------------------------------------------------------------- 1 | package provider 2 | 3 | import ( 4 | "errors" 5 | "regexp" 6 | 7 | "github.com/hashicorp/terraform-plugin-sdk/helper/schema" 8 | "github.com/hashicorp/terraform-plugin-sdk/helper/validation" 9 | "github.com/tpretz/go-zabbix-api" 10 | ) 11 | 12 | // template resource function 13 | func resourceTemplate() *schema.Resource { 14 | return &schema.Resource{ 15 | Create: resourceTemplateCreate, 16 | Read: resourceTemplateRead, 17 | Update: resourceTemplateUpdate, 18 | Delete: resourceTemplateDelete, 19 | Importer: &schema.ResourceImporter{ 20 | State: schema.ImportStatePassthrough, 21 | }, 22 | 23 | Schema: map[string]*schema.Schema{ 24 | "groups": &schema.Schema{ 25 | Type: schema.TypeSet, 26 | Elem: &schema.Schema{ 27 | Type: schema.TypeString, 28 | ValidateFunc: validation.StringMatch(regexp.MustCompile("^[0-9]+$"), "must be a numeric string"), 29 | }, 30 | Required: true, 31 | Description: "Host Group IDs", 32 | }, 33 | "host": &schema.Schema{ 34 | Type: schema.TypeString, 35 | Required: true, 36 | Description: "Template hostname (internal name)", 37 | ValidateFunc: validation.StringIsNotWhiteSpace, 38 | }, 39 | "description": &schema.Schema{ 40 | Type: schema.TypeString, 41 | Optional: true, 42 | Description: "Template description", 43 | }, 44 | "name": &schema.Schema{ 45 | Type: schema.TypeString, 46 | Optional: true, 47 | Description: "Template Display Name (defaults to host)", 48 | }, 49 | "templates": &schema.Schema{ 50 | Type: schema.TypeSet, 51 | Optional: true, 52 | Elem: &schema.Schema{ 53 | Type: schema.TypeString, 54 | ValidateFunc: validation.StringMatch(regexp.MustCompile("^[0-9]+$"), "must be a numeric string"), 55 | }, 56 | Description: "linked templates", 57 | }, 58 | "macro": macroListSchema, 59 | }, 60 | } 61 | } 62 | 63 | func dataTemplate() *schema.Resource { 64 | return &schema.Resource{ 65 | Read: dataTemplateRead, 66 | 67 | Schema: map[string]*schema.Schema{ 68 | "groups": &schema.Schema{ 69 | Type: schema.TypeSet, 70 | Elem: &schema.Schema{ 71 | Type: schema.TypeString, 72 | }, 73 | Computed: true, 74 | Description: "Host Group IDs", 75 | }, 76 | "host": &schema.Schema{ 77 | Type: schema.TypeString, 78 | Optional: true, 79 | Computed: true, 80 | Description: "Template hostname (internal name)", 81 | }, 82 | "description": &schema.Schema{ 83 | Type: schema.TypeString, 84 | Description: "Template description", 85 | Computed: true, 86 | }, 87 | "name": &schema.Schema{ 88 | Type: schema.TypeString, 89 | Optional: true, 90 | Computed: true, 91 | Description: "Template Display Name (defaults to host)", 92 | }, 93 | "macro": macroListSchema, 94 | }, 95 | } 96 | } 97 | 98 | // terraform resource create handler 99 | func resourceTemplateCreate(d *schema.ResourceData, m interface{}) error { 100 | api := m.(*zabbix.API) 101 | 102 | item := buildTemplateObject(d) 103 | items := []zabbix.Template{*item} 104 | 105 | err := api.TemplatesCreate(items) 106 | 107 | if err != nil { 108 | return err 109 | } 110 | 111 | log.Trace("crated template: %+v", items[0]) 112 | 113 | d.SetId(items[0].TemplateID) 114 | 115 | return resourceTemplateRead(d, m) 116 | } 117 | 118 | // terraform template read handler (data source) 119 | func dataTemplateRead(d *schema.ResourceData, m interface{}) error { 120 | 121 | params := zabbix.Params{ 122 | "filter": map[string]interface{}{}, 123 | "selectMacros": "extend", 124 | "selectParentTemplates": "extend", 125 | "selectGroups": "extend", 126 | } 127 | 128 | if v := d.Get("host").(string); v != "" { 129 | params["filter"].(map[string]interface{})["host"] = v 130 | } 131 | 132 | if v := d.Get("name").(string); v != "" { 133 | params["filter"].(map[string]interface{})["name"] = v 134 | } 135 | 136 | if len(params["filter"].(map[string]interface{})) < 1 { 137 | return errors.New("no filter parameters provided") 138 | } 139 | log.Debug("Lookup of template with: %#v", params) 140 | 141 | return templateRead(d, m, params) 142 | } 143 | 144 | // terraform template read handler (resource) 145 | func resourceTemplateRead(d *schema.ResourceData, m interface{}) error { 146 | log.Debug("Lookup of template with id %s", d.Id()) 147 | 148 | return templateRead(d, m, zabbix.Params{ 149 | "templateids": d.Id(), 150 | "selectMacros": "extend", 151 | "selectParentTemplates": "extend", 152 | "selectGroups": "extend", 153 | }) 154 | } 155 | 156 | // generic template read function 157 | func templateRead(d *schema.ResourceData, m interface{}, params zabbix.Params) error { 158 | api := m.(*zabbix.API) 159 | 160 | templates, err := api.TemplatesGet(params) 161 | 162 | if err != nil { 163 | return err 164 | } 165 | 166 | if len(templates) < 1 { 167 | d.SetId("") 168 | return nil 169 | } 170 | if len(templates) > 1 { 171 | return errors.New("multiple templates found") 172 | } 173 | t := templates[0] 174 | 175 | log.Debug("Got template: %+v", t) 176 | 177 | d.Set("description", t.Description) 178 | d.Set("host", t.Host) 179 | d.Set("name", t.Name) 180 | d.Set("macro", flattenMacros(t.UserMacros)) 181 | d.Set("groups", flattenHostGroupIds(t.Groups)) 182 | d.Set("templates", flattenTemplateIds(t.ParentTemplates)) 183 | d.SetId(t.TemplateID) 184 | 185 | return nil 186 | } 187 | 188 | // build a template object from terraform data 189 | func buildTemplateObject(d *schema.ResourceData) *zabbix.Template { 190 | item := zabbix.Template{ 191 | Description: d.Get("description").(string), 192 | Name: d.Get("name").(string), 193 | Host: d.Get("host").(string), 194 | Groups: buildHostGroupIds(d.Get("groups").(*schema.Set)), 195 | LinkedTemplates: buildTemplateIds(d.Get("templates").(*schema.Set)), 196 | } 197 | 198 | item.UserMacros = macroGenerate(d) 199 | return &item 200 | } 201 | 202 | // terraform update resource handler 203 | func resourceTemplateUpdate(d *schema.ResourceData, m interface{}) error { 204 | api := m.(*zabbix.API) 205 | 206 | item := buildTemplateObject(d) 207 | item.TemplateID = d.Id() 208 | 209 | // templates may need a bit extra effort 210 | if d.HasChange("templates") { 211 | old, new := d.GetChange("templates") 212 | diff := old.(*schema.Set).Difference(new.(*schema.Set)) 213 | 214 | // removals, we need to unlink and clear 215 | if diff.Len() > 0 { 216 | item.TemplatesClear = buildTemplateIds(diff) 217 | } 218 | } 219 | 220 | items := []zabbix.Template{*item} 221 | 222 | err := api.TemplatesUpdate(items) 223 | 224 | if err != nil { 225 | return err 226 | } 227 | 228 | return resourceTemplateRead(d, m) 229 | } 230 | 231 | // terraform delete handler 232 | func resourceTemplateDelete(d *schema.ResourceData, m interface{}) error { 233 | api := m.(*zabbix.API) 234 | return api.TemplatesDeleteByIds([]string{d.Id()}) 235 | } 236 | -------------------------------------------------------------------------------- /provider/resource_trigger.go: -------------------------------------------------------------------------------- 1 | package provider 2 | 3 | import ( 4 | "errors" 5 | "regexp" 6 | "strings" 7 | 8 | "github.com/hashicorp/terraform-plugin-sdk/helper/schema" 9 | "github.com/hashicorp/terraform-plugin-sdk/helper/validation" 10 | "github.com/tpretz/go-zabbix-api" 11 | ) 12 | 13 | var TRIGGER_PRIORITY = map[string]zabbix.SeverityType{ 14 | "not_classified": zabbix.NotClassified, 15 | "info": zabbix.Information, 16 | "warn": zabbix.Warning, 17 | "average": zabbix.Average, 18 | "high": zabbix.High, 19 | "disaster": zabbix.Critical, 20 | } 21 | var TRIGGER_PRIORITY_REV = map[zabbix.SeverityType]string{} 22 | var TRIGGER_PRIORITY_ARR = []string{} 23 | 24 | // generate the above structures 25 | var _ = func() bool { 26 | for k, v := range TRIGGER_PRIORITY { 27 | TRIGGER_PRIORITY_REV[v] = k 28 | TRIGGER_PRIORITY_ARR = append(TRIGGER_PRIORITY_ARR, k) 29 | } 30 | return false 31 | }() 32 | 33 | var schemaTrigger = map[string]*schema.Schema{ 34 | // api "description", gui rewrites to name, so shall we 35 | "name": &schema.Schema{ 36 | Type: schema.TypeString, 37 | Required: true, 38 | ValidateFunc: validation.StringIsNotWhiteSpace, 39 | Description: "Trigger name", 40 | }, 41 | "expression": &schema.Schema{ 42 | Type: schema.TypeString, 43 | ValidateFunc: validation.StringIsNotWhiteSpace, 44 | Description: "Trigger Expression", 45 | Required: true, 46 | }, 47 | "comments": &schema.Schema{ 48 | Type: schema.TypeString, 49 | Description: "Trigger comments", 50 | Optional: true, 51 | }, 52 | "priority": &schema.Schema{ 53 | Type: schema.TypeString, 54 | Optional: true, 55 | Description: "Trigger Priority level, one of: " + strings.Join(TRIGGER_PRIORITY_ARR, ", "), 56 | ValidateFunc: validation.StringInSlice(TRIGGER_PRIORITY_ARR, false), 57 | Default: "not_classified", 58 | }, 59 | "enabled": &schema.Schema{ 60 | Type: schema.TypeBool, 61 | Optional: true, 62 | Default: true, 63 | Description: "Enable this trigger", 64 | }, 65 | "multiple": &schema.Schema{ 66 | Type: schema.TypeBool, 67 | Optional: true, 68 | Default: false, 69 | Description: "generate multiple events", 70 | }, 71 | "url": &schema.Schema{ 72 | Type: schema.TypeString, 73 | Optional: true, 74 | Description: "link to url relevent to trigger", 75 | ValidateFunc: validation.IsURLWithHTTPorHTTPS, 76 | }, 77 | "recovery_none": &schema.Schema{ 78 | Type: schema.TypeBool, 79 | Optional: true, 80 | Default: false, 81 | Description: "set recovery mode to none", 82 | }, 83 | "recovery_expression": &schema.Schema{ 84 | Type: schema.TypeString, 85 | Optional: true, 86 | Description: "use recovery expression (recovery_none must not be true)", 87 | }, 88 | "correlation_tag": &schema.Schema{ 89 | Type: schema.TypeString, 90 | Description: "correlation tag", 91 | Optional: true, 92 | }, 93 | "manual_close": &schema.Schema{ 94 | Type: schema.TypeBool, 95 | Optional: true, 96 | Default: false, 97 | Description: "Manual resolution", 98 | }, 99 | "dependencies": &schema.Schema{ 100 | Type: schema.TypeSet, 101 | Optional: true, 102 | Elem: &schema.Schema{ 103 | Type: schema.TypeString, 104 | ValidateFunc: validation.StringMatch(regexp.MustCompile("^[0-9]+$"), "must be a numeric string"), 105 | }, 106 | Description: "Trigger Dependencies", 107 | }, 108 | "tag": &schema.Schema{ 109 | Type: schema.TypeSet, 110 | Optional: true, 111 | Elem: &schema.Resource{ 112 | Schema: map[string]*schema.Schema{ 113 | "key": &schema.Schema{ 114 | Type: schema.TypeString, 115 | Required: true, 116 | ValidateFunc: validation.StringIsNotWhiteSpace, 117 | Description: "Tag Key", 118 | }, 119 | "value": &schema.Schema{ 120 | Type: schema.TypeString, 121 | Optional: true, 122 | Description: "Tag Value", 123 | }, 124 | }, 125 | }, 126 | }, 127 | } 128 | 129 | // terraform resource handler for triggers 130 | func resourceTrigger() *schema.Resource { 131 | return &schema.Resource{ 132 | Create: resourceTriggerCreate(false), 133 | Read: resourceTriggerRead(false), 134 | Update: resourceTriggerUpdate(false), 135 | Delete: resourceTriggerDelete(false), 136 | Importer: &schema.ResourceImporter{ 137 | State: schema.ImportStatePassthrough, 138 | }, 139 | 140 | Schema: schemaTrigger, 141 | } 142 | } 143 | func resourceProtoTrigger() *schema.Resource { 144 | return &schema.Resource{ 145 | Create: resourceTriggerCreate(true), 146 | Read: resourceTriggerRead(true), 147 | Update: resourceTriggerUpdate(true), 148 | Delete: resourceTriggerDelete(true), 149 | Importer: &schema.ResourceImporter{ 150 | State: schema.ImportStatePassthrough, 151 | }, 152 | 153 | Schema: schemaTrigger, 154 | } 155 | } 156 | 157 | // Build Trigger struct for create/modify 158 | func buildTriggerObject(d *schema.ResourceData) zabbix.Trigger { 159 | item := zabbix.Trigger{ 160 | Description: d.Get("name").(string), 161 | Expression: d.Get("expression").(string), 162 | Comments: d.Get("comments").(string), 163 | Priority: TRIGGER_PRIORITY[d.Get("priority").(string)], 164 | Status: 0, 165 | Type: 0, 166 | Url: d.Get("url").(string), 167 | RecoveryMode: 0, 168 | RecoveryExpression: "", 169 | CorrelationMode: 0, 170 | CorrelationTag: "", 171 | ManualClose: 0, 172 | } 173 | 174 | if !d.Get("enabled").(bool) { 175 | item.Status = 1 176 | } 177 | if d.Get("multiple").(bool) { 178 | item.Type = 1 179 | } 180 | 181 | if d.Get("recovery_none").(bool) { 182 | item.RecoveryMode = 2 183 | } else if v := d.Get("recovery_expression").(string); v != "" { 184 | item.RecoveryMode = 1 185 | item.RecoveryExpression = v 186 | } 187 | 188 | if v := d.Get("correlation_tag").(string); v != "" { 189 | item.CorrelationMode = 1 190 | item.CorrelationTag = v 191 | } 192 | 193 | if d.Get("manual_close").(bool) { 194 | item.ManualClose = 1 195 | } 196 | 197 | item.Dependencies = buildTriggerIds(d.Get("dependencies").(*schema.Set)) 198 | item.Tags = tagGenerate(d) 199 | 200 | return item 201 | } 202 | 203 | // create trigger terraform handler 204 | func resourceTriggerCreate(prototype bool) schema.CreateFunc { 205 | return func(d *schema.ResourceData, m interface{}) error { 206 | api := m.(*zabbix.API) 207 | 208 | item := buildTriggerObject(d) 209 | 210 | items := []zabbix.Trigger{item} 211 | 212 | var err error 213 | if prototype { 214 | err = api.ProtoTriggersCreate(items) 215 | } else { 216 | err = api.TriggersCreate(items) 217 | } 218 | 219 | if err != nil { 220 | return err 221 | } 222 | 223 | log.Trace("crated trigger: %+v", items[0]) 224 | 225 | d.SetId(items[0].TriggerID) 226 | 227 | return resourceTriggerRead(prototype)(d, m) 228 | } 229 | } 230 | 231 | // read tirgger terraform handler 232 | func resourceTriggerRead(prototype bool) schema.ReadFunc { 233 | return func(d *schema.ResourceData, m interface{}) error { 234 | api := m.(*zabbix.API) 235 | 236 | log.Debug("Lookup of trigger with id %s", d.Id()) 237 | 238 | params := zabbix.Params{ 239 | "triggerids": d.Id(), 240 | "expandExpression": "extend", 241 | "selectDependencies": "extend", 242 | "selectTags": "extend", 243 | } 244 | 245 | var triggers zabbix.Triggers 246 | var err error 247 | 248 | if prototype { 249 | triggers, err = api.ProtoTriggersGet(params) 250 | } else { 251 | triggers, err = api.TriggersGet(params) 252 | } 253 | 254 | if err != nil { 255 | return err 256 | } 257 | 258 | if len(triggers) < 1 { 259 | d.SetId("") 260 | return nil 261 | } 262 | if len(triggers) > 1 { 263 | return errors.New("multiple triggers found") 264 | } 265 | t := triggers[0] 266 | 267 | log.Debug("Got trigger: %+v", t) 268 | 269 | d.Set("name", t.Description) 270 | d.Set("expression", t.Expression) 271 | d.Set("comments", t.Comments) 272 | d.Set("priority", TRIGGER_PRIORITY_REV[t.Priority]) 273 | d.Set("enabled", t.Status == 0) 274 | d.Set("multiple", t.Type == 1) 275 | d.Set("url", t.Url) 276 | d.Set("recovery_expression", t.RecoveryExpression) 277 | d.Set("correlation_tag", t.CorrelationTag) 278 | d.Set("manual_close", t.ManualClose == 1) 279 | d.Set("tag", flattenTags(t.Tags)) 280 | 281 | if t.RecoveryMode == 2 { 282 | d.Set("recovery_none", true) 283 | } else { 284 | d.Set("recovery_none", false) 285 | } 286 | 287 | // should not occur, but need to express somehow, in a way that allows cleanup 288 | if t.RecoveryMode == 1 && t.RecoveryExpression == "" { 289 | // this should trigger a mismatch, and by setting to 0 len str it should flip recovery mode 290 | d.Set("recovery_expression", "") 291 | } 292 | if t.CorrelationMode == 1 && t.CorrelationTag == "" { 293 | // this should trigger a mismatch, and by setting to 0 len str it should flip recovery mode 294 | d.Set("correlation_tag", "") 295 | } 296 | 297 | dependenciesSet := schema.NewSet(schema.HashString, []interface{}{}) 298 | for _, v := range t.Dependencies { 299 | dependenciesSet.Add(v.TriggerID) 300 | } 301 | d.Set("dependencies", dependenciesSet) 302 | 303 | return nil 304 | } 305 | } 306 | 307 | // update trigger terraform handler 308 | func resourceTriggerUpdate(prototype bool) schema.UpdateFunc { 309 | return func(d *schema.ResourceData, m interface{}) error { 310 | api := m.(*zabbix.API) 311 | 312 | item := buildTriggerObject(d) 313 | 314 | item.TriggerID = d.Id() 315 | 316 | items := []zabbix.Trigger{item} 317 | 318 | var err error 319 | 320 | if prototype { 321 | err = api.ProtoTriggersUpdate(items) 322 | } else { 323 | err = api.TriggersUpdate(items) 324 | } 325 | 326 | if err != nil { 327 | return err 328 | } 329 | 330 | return resourceTriggerRead(prototype)(d, m) 331 | } 332 | } 333 | 334 | // delete trigger terraform handler 335 | func resourceTriggerDelete(prototype bool) schema.DeleteFunc { 336 | return func(d *schema.ResourceData, m interface{}) error { 337 | api := m.(*zabbix.API) 338 | if prototype { 339 | return api.ProtoTriggersDeleteByIds([]string{d.Id()}) 340 | } 341 | return api.TriggersDeleteByIds([]string{d.Id()}) 342 | } 343 | } 344 | -------------------------------------------------------------------------------- /provider/resource_snmp_common.go: -------------------------------------------------------------------------------- 1 | package provider 2 | 3 | import ( 4 | "strings" 5 | 6 | "github.com/hashicorp/terraform-plugin-sdk/helper/schema" 7 | "github.com/hashicorp/terraform-plugin-sdk/helper/validation" 8 | "github.com/tpretz/go-zabbix-api" 9 | ) 10 | 11 | var SNMP_LOOKUP = map[string]zabbix.ItemType{ 12 | "1": zabbix.SNMPv1Agent, 13 | "2": zabbix.SNMPv2Agent, 14 | "3": zabbix.SNMPv3Agent, 15 | } 16 | var SNMP_LOOKUP_REV = map[zabbix.ItemType]string{} 17 | var SNMP_LOOKUP_ARR = []string{} 18 | 19 | var SNMP_AUTHPROTO = map[string]string{ 20 | "md5": "0", 21 | "sha": "1", 22 | } 23 | var SNMP_AUTHPROTO_REV = map[string]string{} 24 | var SNMP_AUTHPROTO_ARR = []string{} 25 | 26 | var SNMP_PRIVPROTO = map[string]string{ 27 | "des": "0", 28 | "aes": "1", 29 | } 30 | var SNMP_PRIVPROTO_REV = map[string]string{} 31 | var SNMP_PRIVPROTO_ARR = []string{} 32 | 33 | var SNMP_SECLEVEL = map[string]string{ 34 | "noauthnopriv": "0", 35 | "authnopriv": "1", 36 | "authpriv": "2", 37 | } 38 | var SNMP_SECLEVEL_REV = map[string]string{} 39 | var SNMP_SECLEVEL_ARR = []string{} 40 | 41 | // generate the above structures 42 | var _ = func() bool { 43 | for k, v := range SNMP_LOOKUP { 44 | SNMP_LOOKUP_REV[v] = k 45 | SNMP_LOOKUP_ARR = append(SNMP_LOOKUP_ARR, k) 46 | } 47 | for k, v := range SNMP_AUTHPROTO { 48 | SNMP_AUTHPROTO_REV[v] = k 49 | SNMP_AUTHPROTO_ARR = append(SNMP_AUTHPROTO_ARR, k) 50 | } 51 | for k, v := range SNMP_PRIVPROTO { 52 | SNMP_PRIVPROTO_REV[v] = k 53 | SNMP_PRIVPROTO_ARR = append(SNMP_PRIVPROTO_ARR, k) 54 | } 55 | for k, v := range SNMP_SECLEVEL { 56 | SNMP_SECLEVEL_REV[v] = k 57 | SNMP_SECLEVEL_ARR = append(SNMP_SECLEVEL_ARR, k) 58 | } 59 | return false 60 | }() 61 | 62 | var schemaSnmp = map[string]*schema.Schema{ 63 | "snmp_version": &schema.Schema{ 64 | Type: schema.TypeString, 65 | Optional: true, 66 | Default: "2", 67 | Description: "SNMP Version, one of: " + strings.Join(SNMP_LOOKUP_ARR, ", "), 68 | ValidateFunc: validation.StringInSlice(SNMP_LOOKUP_ARR, false), 69 | }, 70 | "snmp_oid": &schema.Schema{ 71 | Type: schema.TypeString, 72 | ValidateFunc: validation.StringIsNotWhiteSpace, 73 | Description: "SNMP OID", 74 | Required: true, 75 | }, 76 | "snmp_community": &schema.Schema{ 77 | Type: schema.TypeString, 78 | Optional: true, 79 | Description: "SNMP Community (v1/v2 only)", 80 | ValidateFunc: validation.StringIsNotWhiteSpace, 81 | Default: "{$SNMP_COMMUNITY}", 82 | }, 83 | "snmp3_authpassphrase": &schema.Schema{ 84 | Type: schema.TypeString, 85 | Optional: true, 86 | Description: "Authentication Passphrase (v3 only)", 87 | ValidateFunc: validation.StringIsNotWhiteSpace, 88 | Default: "{$SNMP3_AUTHPASSPHRASE}", 89 | }, 90 | "snmp3_authprotocol": &schema.Schema{ 91 | Type: schema.TypeString, 92 | Optional: true, 93 | Description: "Authentication Protocol (v3 only), one of: " + strings.Join(SNMP_AUTHPROTO_ARR, ", "), 94 | ValidateFunc: validation.StringInSlice(SNMP_AUTHPROTO_ARR, false), 95 | Default: "sha", 96 | }, 97 | "snmp3_contextname": &schema.Schema{ 98 | Type: schema.TypeString, 99 | Optional: true, 100 | Description: "Context Name (v3 only)", 101 | ValidateFunc: validation.StringIsNotWhiteSpace, 102 | Default: "{$SNMP3_CONTEXTNAME}", 103 | }, 104 | "snmp3_privpassphrase": &schema.Schema{ 105 | Type: schema.TypeString, 106 | Optional: true, 107 | Description: "Priv Passphrase (v3 only)", 108 | ValidateFunc: validation.StringIsNotWhiteSpace, 109 | Default: "{$SNMP3_PRIVPASSPHRASE}", 110 | }, 111 | "snmp3_privprotocol": &schema.Schema{ 112 | Type: schema.TypeString, 113 | Optional: true, 114 | Description: "Priv Protocol (v3 only), one of: " + strings.Join(SNMP_PRIVPROTO_ARR, ", "), 115 | ValidateFunc: validation.StringInSlice(SNMP_PRIVPROTO_ARR, false), 116 | Default: "aes", 117 | }, 118 | "snmp3_securitylevel": &schema.Schema{ 119 | Type: schema.TypeString, 120 | Optional: true, 121 | Description: "Security Level (v3 only), one of: " + strings.Join(SNMP_SECLEVEL_ARR, ", "), 122 | ValidateFunc: validation.StringInSlice(SNMP_SECLEVEL_ARR, false), 123 | Default: "authpriv", 124 | }, 125 | "snmp3_securityname": &schema.Schema{ 126 | Type: schema.TypeString, 127 | Optional: true, 128 | Description: "Security Name (v3 only)", 129 | ValidateFunc: validation.StringIsNotWhiteSpace, 130 | Default: "{$SNMP3_SECURITYNAME}", 131 | }, 132 | } 133 | 134 | // terraform resource handler for item type 135 | func resourceItemSnmp() *schema.Resource { 136 | return &schema.Resource{ 137 | Create: itemGetCreateWrapper(itemSnmpModFunc, itemSnmpReadFunc), 138 | Read: itemGetReadWrapper(itemSnmpReadFunc), 139 | Update: itemGetUpdateWrapper(itemSnmpModFunc, itemSnmpReadFunc), 140 | Delete: resourceItemDelete, 141 | Importer: &schema.ResourceImporter{ 142 | State: schema.ImportStatePassthrough, 143 | }, 144 | Schema: mergeSchemas(itemCommonSchema, itemDelaySchema, itemInterfaceSchema, schemaSnmp), 145 | } 146 | } 147 | func resourceProtoItemSnmp() *schema.Resource { 148 | return &schema.Resource{ 149 | Create: protoItemGetCreateWrapper(itemSnmpModFunc, itemSnmpReadFunc), 150 | Read: protoItemGetReadWrapper(itemSnmpReadFunc), 151 | Update: protoItemGetUpdateWrapper(itemSnmpModFunc, itemSnmpReadFunc), 152 | Delete: resourceProtoItemDelete, 153 | Importer: &schema.ResourceImporter{ 154 | State: schema.ImportStatePassthrough, 155 | }, 156 | Schema: mergeSchemas(itemCommonSchema, itemDelaySchema, itemInterfaceSchema, itemPrototypeSchema, schemaSnmp), 157 | } 158 | } 159 | 160 | func resourceLLDSnmp() *schema.Resource { 161 | return &schema.Resource{ 162 | Create: lldGetCreateWrapper(lldSnmpModFunc, lldSnmpReadFunc), 163 | Read: lldGetReadWrapper(lldSnmpReadFunc), 164 | Update: lldGetUpdateWrapper(lldSnmpModFunc, lldSnmpReadFunc), 165 | Delete: resourceLLDDelete, 166 | Importer: &schema.ResourceImporter{ 167 | State: schema.ImportStatePassthrough, 168 | }, 169 | Schema: mergeSchemas(lldCommonSchema, lldInterfaceSchema, schemaSnmp), 170 | } 171 | } 172 | 173 | // Custom mod handler for item type 174 | func itemSnmpModFunc(d *schema.ResourceData, m interface{}, item *zabbix.Item) { 175 | api := m.(*zabbix.API) 176 | item.InterfaceID = d.Get("interfaceid").(string) 177 | item.Delay = d.Get("delay").(string) 178 | 179 | item.SNMPOid = d.Get("snmp_oid").(string) 180 | 181 | // new mode 182 | if api.Config.Version >= 50000 { 183 | item.Type = zabbix.SNMPAgent 184 | } else { // old mode 185 | item.Type = SNMP_LOOKUP[d.Get("snmp_version").(string)] 186 | switch item.Type { 187 | case zabbix.SNMPv1Agent, zabbix.SNMPv2Agent: 188 | item.SNMPCommunity = d.Get("snmp_community").(string) 189 | case zabbix.SNMPv3Agent: 190 | item.SNMPv3AuthPassphrase = d.Get("snmp3_authpassphrase").(string) 191 | item.SNMPv3AuthProtocol = SNMP_AUTHPROTO[d.Get("snmp3_authprotocol").(string)] 192 | item.SNMPv3ContextName = d.Get("snmp3_contextname").(string) 193 | item.SNMPv3PrivPasshrase = d.Get("snmp3_privpassphrase").(string) 194 | item.SNMPv3PrivProtocol = SNMP_PRIVPROTO[d.Get("snmp3_privprotocol").(string)] 195 | item.SNMPv3SecurityLevel = SNMP_SECLEVEL[d.Get("snmp3_securitylevel").(string)] 196 | item.SNMPv3SecurityName = d.Get("snmp3_securityname").(string) 197 | } 198 | } 199 | } 200 | 201 | // Also for LLD Discovery SNMP 202 | func lldSnmpModFunc(d *schema.ResourceData, m interface{}, item *zabbix.LLDRule) { 203 | api := m.(*zabbix.API) 204 | item.InterfaceID = d.Get("interfaceid").(string) 205 | 206 | item.SNMPOid = d.Get("snmp_oid").(string) 207 | 208 | if api.Config.Version >= 50000 { 209 | item.Type = zabbix.SNMPAgent 210 | } else { // old mode 211 | item.Type = SNMP_LOOKUP[d.Get("snmp_version").(string)] 212 | switch item.Type { 213 | case zabbix.SNMPv1Agent, zabbix.SNMPv2Agent: 214 | item.SNMPCommunity = d.Get("snmp_community").(string) 215 | case zabbix.SNMPv3Agent: 216 | item.SNMPv3AuthPassphrase = d.Get("snmp3_authpassphrase").(string) 217 | item.SNMPv3AuthProtocol = SNMP_AUTHPROTO[d.Get("snmp3_authprotocol").(string)] 218 | item.SNMPv3ContextName = d.Get("snmp3_contextname").(string) 219 | item.SNMPv3PrivPasshrase = d.Get("snmp3_privpassphrase").(string) 220 | item.SNMPv3PrivProtocol = SNMP_PRIVPROTO[d.Get("snmp3_privprotocol").(string)] 221 | item.SNMPv3SecurityLevel = SNMP_SECLEVEL[d.Get("snmp3_securitylevel").(string)] 222 | item.SNMPv3SecurityName = d.Get("snmp3_securityname").(string) 223 | } 224 | } 225 | } 226 | 227 | // Custom read handler for item type 228 | func itemSnmpReadFunc(d *schema.ResourceData, m interface{}, item *zabbix.Item) { 229 | api := m.(*zabbix.API) 230 | d.Set("interfaceid", item.InterfaceID) 231 | d.Set("delay", item.Delay) 232 | 233 | d.Set("snmp_oid", item.SNMPOid) 234 | 235 | if api.Config.Version < 50000 { 236 | d.Set("type", SNMP_LOOKUP_REV[item.Type]) // may be null, check 237 | switch item.Type { 238 | case zabbix.SNMPv1Agent, zabbix.SNMPv2Agent: 239 | d.Set("snmp_community", item.SNMPCommunity) 240 | case zabbix.SNMPv3Agent: 241 | d.Set("snmp3_authpassphrase", item.SNMPv3AuthPassphrase) 242 | d.Set("snmp3_authprotocol", SNMP_AUTHPROTO_REV[item.SNMPv3AuthProtocol]) 243 | d.Set("snmp3_contextname", item.SNMPv3ContextName) 244 | d.Set("snmp3_privpassphrase", item.SNMPv3PrivPasshrase) 245 | d.Set("snmp3_privprotocol", SNMP_PRIVPROTO_REV[item.SNMPv3PrivProtocol]) 246 | d.Set("snmp3_securitylevel", SNMP_SECLEVEL_REV[item.SNMPv3SecurityLevel]) 247 | d.Set("snmp3_securityname", item.SNMPv3SecurityName) 248 | } 249 | } 250 | } 251 | 252 | // Also for LLD Discovery SNMP 253 | func lldSnmpReadFunc(d *schema.ResourceData, m interface{}, item *zabbix.LLDRule) { 254 | api := m.(*zabbix.API) 255 | d.Set("interfaceid", item.InterfaceID) 256 | 257 | d.Set("snmp_oid", item.SNMPOid) 258 | 259 | if api.Config.Version < 50000 { 260 | d.Set("type", SNMP_LOOKUP_REV[item.Type]) // may be null, check 261 | switch item.Type { 262 | case zabbix.SNMPv1Agent, zabbix.SNMPv2Agent: 263 | d.Set("snmp_community", item.SNMPCommunity) 264 | case zabbix.SNMPv3Agent: 265 | d.Set("snmp3_authpassphrase", item.SNMPv3AuthPassphrase) 266 | d.Set("snmp3_authprotocol", SNMP_AUTHPROTO_REV[item.SNMPv3AuthProtocol]) 267 | d.Set("snmp3_contextname", item.SNMPv3ContextName) 268 | d.Set("snmp3_privpassphrase", item.SNMPv3PrivPasshrase) 269 | d.Set("snmp3_privprotocol", SNMP_PRIVPROTO_REV[item.SNMPv3PrivProtocol]) 270 | d.Set("snmp3_securitylevel", SNMP_SECLEVEL_REV[item.SNMPv3SecurityLevel]) 271 | d.Set("snmp3_securityname", item.SNMPv3SecurityName) 272 | } 273 | } 274 | } 275 | -------------------------------------------------------------------------------- /provider/resource_http_common.go: -------------------------------------------------------------------------------- 1 | package provider 2 | 3 | import ( 4 | "strings" 5 | 6 | "github.com/hashicorp/terraform-plugin-sdk/helper/schema" 7 | "github.com/hashicorp/terraform-plugin-sdk/helper/validation" 8 | "github.com/tpretz/go-zabbix-api" 9 | ) 10 | 11 | var HTTP_METHODS = map[string]string{ 12 | "get": "0", 13 | "post": "1", 14 | "put": "2", 15 | "head": "3", 16 | } 17 | var HTTP_METHODS_REV = map[string]string{} 18 | var HTTP_METHODS_ARR = []string{} 19 | 20 | var HTTP_RETRIEVEMODE = map[string]string{ 21 | "body": "0", 22 | "headers": "1", 23 | "both": "2", 24 | } 25 | var HTTP_RETRIEVEMODE_REV = map[string]string{} 26 | var HTTP_RETRIEVEMODE_ARR = []string{} 27 | 28 | var HTTP_POSTTYPE = map[string]string{ 29 | "raw": "0", 30 | "json": "2", 31 | "xml": "3", 32 | } 33 | var HTTP_POSTTYPE_REV = map[string]string{} 34 | var HTTP_POSTTYPE_ARR = []string{} 35 | 36 | var HTTP_AUTHTYPE = map[string]string{ 37 | "none": "0", 38 | "basic": "1", 39 | "ntlm": "2", 40 | "kerberos": "3", 41 | } 42 | var HTTP_AUTHTYPE_REV = map[string]string{} 43 | var HTTP_AUTHTYPE_ARR = []string{} 44 | 45 | // generate the above structures 46 | var _ = func() bool { 47 | for k, v := range HTTP_METHODS { 48 | HTTP_METHODS_REV[v] = k 49 | HTTP_METHODS_ARR = append(HTTP_METHODS_ARR, k) 50 | } 51 | for k, v := range HTTP_POSTTYPE { 52 | HTTP_POSTTYPE_REV[v] = k 53 | HTTP_POSTTYPE_ARR = append(HTTP_POSTTYPE_ARR, k) 54 | } 55 | for k, v := range HTTP_RETRIEVEMODE { 56 | HTTP_RETRIEVEMODE_REV[v] = k 57 | HTTP_RETRIEVEMODE_ARR = append(HTTP_RETRIEVEMODE_ARR, k) 58 | } 59 | for k, v := range HTTP_AUTHTYPE { 60 | HTTP_AUTHTYPE_REV[v] = k 61 | HTTP_AUTHTYPE_ARR = append(HTTP_AUTHTYPE_ARR, k) 62 | } 63 | return false 64 | }() 65 | 66 | var schemaHttpHeader = &schema.Schema{ 67 | Type: schema.TypeMap, 68 | Optional: true, 69 | Elem: &schema.Schema{ 70 | Type: schema.TypeString, 71 | Description: "Header Value", 72 | ValidateFunc: validation.StringIsNotWhiteSpace, 73 | }, 74 | } 75 | 76 | var schemaHttp = map[string]*schema.Schema{ 77 | "url": &schema.Schema{ 78 | Type: schema.TypeString, 79 | Description: "url to probe", 80 | ValidateFunc: validation.StringIsNotWhiteSpace, 81 | Required: true, 82 | }, 83 | "request_method": &schema.Schema{ 84 | Type: schema.TypeString, 85 | Optional: true, 86 | Description: "HTTP request method, one of: " + strings.Join(HTTP_METHODS_ARR, ", "), 87 | ValidateFunc: validation.StringInSlice(HTTP_METHODS_ARR, false), 88 | Default: "get", 89 | }, 90 | "post_type": &schema.Schema{ 91 | Type: schema.TypeString, 92 | Optional: true, 93 | Description: "HTTP post type, one of: " + strings.Join(HTTP_POSTTYPE_ARR, ", "), 94 | ValidateFunc: validation.StringInSlice(HTTP_POSTTYPE_ARR, false), 95 | Default: "body", 96 | }, 97 | "retrieve_mode": &schema.Schema{ 98 | Type: schema.TypeString, 99 | Optional: true, 100 | Description: "HTTP retrieve mode, one of: " + strings.Join(HTTP_RETRIEVEMODE_ARR, ", "), 101 | ValidateFunc: validation.StringInSlice(HTTP_RETRIEVEMODE_ARR, false), 102 | Default: "body", 103 | }, 104 | "auth_type": &schema.Schema{ 105 | Type: schema.TypeString, 106 | Optional: true, 107 | Description: "HTTP auth type, one of: " + strings.Join(HTTP_AUTHTYPE_ARR, ", "), 108 | ValidateFunc: validation.StringInSlice(HTTP_AUTHTYPE_ARR, false), 109 | Default: "none", 110 | }, 111 | "username": &schema.Schema{ 112 | Type: schema.TypeString, 113 | Optional: true, 114 | Description: "Authentication Username", 115 | }, 116 | "proxy": &schema.Schema{ 117 | Type: schema.TypeString, 118 | Optional: true, 119 | Description: "HTTP proxy connection string", 120 | }, 121 | "password": &schema.Schema{ 122 | Type: schema.TypeString, 123 | Optional: true, 124 | Sensitive: true, 125 | Description: "Authentication Password", 126 | }, 127 | "headers": schemaHttpHeader, 128 | "posts": &schema.Schema{ 129 | Type: schema.TypeString, 130 | Optional: true, 131 | Description: "POST data to send in request", 132 | }, 133 | "status_codes": &schema.Schema{ 134 | Type: schema.TypeString, 135 | Optional: true, 136 | Default: "200", 137 | Description: "http status code", 138 | }, 139 | "timeout": &schema.Schema{ 140 | Type: schema.TypeString, 141 | Optional: true, 142 | Description: "http request timeout", 143 | Default: "3s", 144 | }, 145 | "verify_host": &schema.Schema{ 146 | Type: schema.TypeBool, 147 | Optional: true, 148 | Description: "https verify host", 149 | Default: true, 150 | }, 151 | "verify_peer": &schema.Schema{ 152 | Type: schema.TypeBool, 153 | Description: "https verify peer", 154 | Optional: true, 155 | Default: true, 156 | }, 157 | "follow_redirects": &schema.Schema{ 158 | Type: schema.TypeBool, 159 | Description: "follow http redirects", 160 | Optional: true, 161 | Default: true, 162 | }, 163 | } 164 | 165 | // resourceItemHttp Http item resource handler 166 | func resourceItemHttp() *schema.Resource { 167 | return &schema.Resource{ 168 | Create: itemGetCreateWrapper(itemHttpModFunc, itemHttpReadFunc), 169 | Read: itemGetReadWrapper(itemHttpReadFunc), 170 | Update: itemGetUpdateWrapper(itemHttpModFunc, itemHttpReadFunc), 171 | Delete: resourceItemDelete, 172 | Importer: &schema.ResourceImporter{ 173 | State: schema.ImportStatePassthrough, 174 | }, 175 | 176 | Schema: mergeSchemas(itemCommonSchema, itemDelaySchema, itemInterfaceSchema, schemaHttp), 177 | } 178 | } 179 | func resourceProtoItemHttp() *schema.Resource { 180 | return &schema.Resource{ 181 | Create: protoItemGetCreateWrapper(itemHttpModFunc, itemHttpReadFunc), 182 | Read: protoItemGetReadWrapper(itemHttpReadFunc), 183 | Update: protoItemGetUpdateWrapper(itemHttpModFunc, itemHttpReadFunc), 184 | Delete: resourceProtoItemDelete, 185 | Importer: &schema.ResourceImporter{ 186 | State: schema.ImportStatePassthrough, 187 | }, 188 | 189 | Schema: mergeSchemas(itemCommonSchema, itemDelaySchema, itemInterfaceSchema, itemPrototypeSchema, schemaHttp), 190 | } 191 | } 192 | func resourceLLDHttp() *schema.Resource { 193 | return &schema.Resource{ 194 | Create: lldGetCreateWrapper(lldHttpModFunc, lldHttpReadFunc), 195 | Read: lldGetReadWrapper(lldHttpReadFunc), 196 | Update: lldGetUpdateWrapper(lldHttpModFunc, lldHttpReadFunc), 197 | Delete: resourceLLDDelete, 198 | Importer: &schema.ResourceImporter{ 199 | State: schema.ImportStatePassthrough, 200 | }, 201 | 202 | Schema: mergeSchemas(lldCommonSchema, itemInterfaceSchema, schemaHttp), 203 | } 204 | } 205 | 206 | func httpGenerateHeaders(d *schema.ResourceData) (headers zabbix.HttpHeaders) { 207 | m := d.Get("headers").(map[string]interface{}) 208 | headers = zabbix.HttpHeaders{} 209 | 210 | for k, v := range m { 211 | headers[k] = v.(string) 212 | } 213 | 214 | return 215 | } 216 | 217 | func httpFlattenHeaders(headers zabbix.HttpHeaders) (ret map[string]interface{}) { 218 | ret = map[string]interface{}{} 219 | for k, v := range headers { 220 | ret[k] = v 221 | } 222 | return 223 | } 224 | 225 | // http item modify custom function 226 | func itemHttpModFunc(d *schema.ResourceData, m interface{}, item *zabbix.Item) { 227 | item.InterfaceID = d.Get("interfaceid").(string) 228 | item.Url = d.Get("url").(string) 229 | item.Delay = d.Get("delay").(string) 230 | item.RequestMethod = HTTP_METHODS[d.Get("request_method").(string)] 231 | item.PostType = HTTP_POSTTYPE[d.Get("post_type").(string)] 232 | item.RetrieveMode = HTTP_RETRIEVEMODE[d.Get("retrieve_mode").(string)] 233 | item.AuthType = HTTP_AUTHTYPE[d.Get("auth_type").(string)] 234 | item.Username = d.Get("username").(string) 235 | item.Proxy = d.Get("proxy").(string) 236 | item.Password = d.Get("password").(string) 237 | item.Posts = d.Get("posts").(string) 238 | item.StatusCodes = d.Get("status_codes").(string) 239 | item.Timeout = d.Get("timeout").(string) 240 | item.Type = zabbix.HTTPAgent 241 | item.VerifyHost = "0" 242 | item.VerifyPeer = "0" 243 | item.FollowRedirects = "1" 244 | 245 | if d.Get("verify_host").(bool) { 246 | item.VerifyHost = "1" 247 | } 248 | 249 | if d.Get("verify_peer").(bool) { 250 | item.VerifyPeer = "1" 251 | } 252 | 253 | if !d.Get("follow_redirects").(bool) { 254 | item.FollowRedirects = "0" 255 | } 256 | item.Headers = httpGenerateHeaders(d) 257 | } 258 | func lldHttpModFunc(d *schema.ResourceData, m interface{}, item *zabbix.LLDRule) { 259 | item.InterfaceID = d.Get("interfaceid").(string) 260 | item.Url = d.Get("url").(string) 261 | item.RequestMethod = HTTP_METHODS[d.Get("request_method").(string)] 262 | item.PostType = HTTP_POSTTYPE[d.Get("post_type").(string)] 263 | item.RetrieveMode = HTTP_RETRIEVEMODE[d.Get("retrieve_mode").(string)] 264 | item.AuthType = HTTP_AUTHTYPE[d.Get("auth_type").(string)] 265 | item.Username = d.Get("username").(string) 266 | item.Proxy = d.Get("proxy").(string) 267 | item.Password = d.Get("password").(string) 268 | item.Posts = d.Get("posts").(string) 269 | item.StatusCodes = d.Get("status_codes").(string) 270 | item.Timeout = d.Get("timeout").(string) 271 | item.Type = zabbix.HTTPAgent 272 | item.VerifyHost = "0" 273 | item.VerifyPeer = "0" 274 | item.FollowRedirects = "1" 275 | 276 | if d.Get("verify_host").(bool) { 277 | item.VerifyHost = "1" 278 | } 279 | 280 | if d.Get("verify_peer").(bool) { 281 | item.VerifyPeer = "1" 282 | } 283 | 284 | if !d.Get("follow_redirects").(bool) { 285 | item.FollowRedirects = "0" 286 | } 287 | item.Headers = httpGenerateHeaders(d) 288 | } 289 | 290 | // http item read custom function 291 | func itemHttpReadFunc(d *schema.ResourceData, m interface{}, item *zabbix.Item) { 292 | d.Set("interfaceid", item.InterfaceID) 293 | d.Set("url", item.Url) 294 | d.Set("delay", item.Delay) 295 | d.Set("request_method", HTTP_METHODS_REV[item.RequestMethod]) 296 | d.Set("post_type", HTTP_POSTTYPE_REV[item.PostType]) 297 | d.Set("retrieve_mode", HTTP_RETRIEVEMODE_REV[item.RetrieveMode]) 298 | d.Set("auth_type", HTTP_AUTHTYPE_REV[item.AuthType]) 299 | d.Set("username", item.Username) 300 | d.Set("proxy", item.Proxy) 301 | d.Set("password", item.Password) 302 | d.Set("posts", item.Posts) 303 | d.Set("status_codes", item.StatusCodes) 304 | d.Set("timeout", item.Timeout) 305 | d.Set("verify_host", item.VerifyHost == "1") 306 | d.Set("verify_peer", item.VerifyPeer == "1") 307 | d.Set("follow_redirects", item.FollowRedirects != "0") 308 | d.Set("headers", httpFlattenHeaders(item.Headers)) 309 | } 310 | func lldHttpReadFunc(d *schema.ResourceData, m interface{}, item *zabbix.LLDRule) { 311 | d.Set("interfaceid", item.InterfaceID) 312 | d.Set("url", item.Url) 313 | d.Set("request_method", HTTP_METHODS_REV[item.RequestMethod]) 314 | d.Set("post_type", HTTP_POSTTYPE_REV[item.PostType]) 315 | d.Set("retrieve_mode", HTTP_RETRIEVEMODE_REV[item.RetrieveMode]) 316 | d.Set("auth_type", HTTP_AUTHTYPE_REV[item.AuthType]) 317 | d.Set("username", item.Username) 318 | d.Set("proxy", item.Proxy) 319 | d.Set("password", item.Password) 320 | d.Set("posts", item.Posts) 321 | d.Set("status_codes", item.StatusCodes) 322 | d.Set("timeout", item.Timeout) 323 | d.Set("verify_host", item.VerifyHost == "1") 324 | d.Set("verify_peer", item.VerifyPeer == "1") 325 | d.Set("follow_redirects", item.FollowRedirects != "0") 326 | d.Set("headers", httpFlattenHeaders(item.Headers)) 327 | } 328 | -------------------------------------------------------------------------------- /provider/common_item.go: -------------------------------------------------------------------------------- 1 | package provider 2 | 3 | import ( 4 | "errors" 5 | "fmt" 6 | "regexp" 7 | "strings" 8 | 9 | "github.com/hashicorp/terraform-plugin-sdk/helper/schema" 10 | "github.com/hashicorp/terraform-plugin-sdk/helper/validation" 11 | "github.com/tpretz/go-zabbix-api" 12 | ) 13 | 14 | // Item Type Conversion and lookup tables 15 | var ITEM_VALUE_TYPES = map[string]zabbix.ValueType{ 16 | "float": zabbix.Float, 17 | "character": zabbix.Character, 18 | "log": zabbix.Log, 19 | "unsigned": zabbix.Unsigned, 20 | "text": zabbix.Text, 21 | } 22 | var ITEM_VALUE_TYPES_REV = map[zabbix.ValueType]string{ 23 | zabbix.Float: "float", 24 | zabbix.Character: "character", 25 | zabbix.Log: "log", 26 | zabbix.Unsigned: "unsigned", 27 | zabbix.Text: "text", 28 | } 29 | var ITEM_VALUE_TYPES_ARR = []string{ 30 | "float", 31 | "character", 32 | "log", 33 | "unsigned", 34 | "text", 35 | } 36 | 37 | // common schema elements for all item types 38 | var itemCommonSchema = map[string]*schema.Schema{ 39 | "hostid": &schema.Schema{ 40 | Type: schema.TypeString, 41 | Required: true, 42 | ForceNew: true, 43 | Description: "Host ID", 44 | ValidateFunc: validation.StringMatch(regexp.MustCompile("^[0-9]+$"), "must be numeric"), 45 | }, 46 | "key": &schema.Schema{ 47 | Type: schema.TypeString, 48 | Description: "Item KEY", 49 | ValidateFunc: validation.StringIsNotWhiteSpace, 50 | Required: true, 51 | }, 52 | "name": &schema.Schema{ 53 | Type: schema.TypeString, 54 | Description: "Item Name", 55 | ValidateFunc: validation.StringIsNotWhiteSpace, 56 | Required: true, 57 | }, 58 | "history": &schema.Schema{ 59 | Type: schema.TypeString, 60 | Description: "Item History", 61 | ValidateFunc: validation.StringIsNotWhiteSpace, 62 | Default: "90d", 63 | Optional: true, 64 | }, 65 | "trends": &schema.Schema{ 66 | Type: schema.TypeString, 67 | Description: "Item Trends", 68 | ValidateFunc: validation.StringIsNotWhiteSpace, 69 | //Default: "365d", 70 | Optional: true, 71 | Computed: true, 72 | }, 73 | "valuetype": &schema.Schema{ 74 | Type: schema.TypeString, 75 | ValidateFunc: validation.StringInSlice(ITEM_VALUE_TYPES_ARR, false), 76 | Description: "Item Value Type, one of: " + strings.Join(ITEM_VALUE_TYPES_ARR, ", "), 77 | Required: true, 78 | }, 79 | "preprocessor": itemPreprocessorSchema, 80 | "applications": &schema.Schema{ 81 | Type: schema.TypeSet, 82 | Description: "Application IDs to associate this item with", 83 | Elem: &schema.Schema{ 84 | Type: schema.TypeString, 85 | ValidateFunc: validation.StringMatch(regexp.MustCompile("^[0-9]+$"), "must be a numeric string"), 86 | }, 87 | Optional: true, 88 | }, 89 | "tag": &schema.Schema{ 90 | Type: schema.TypeSet, 91 | Optional: true, 92 | Elem: &schema.Resource{ 93 | Schema: map[string]*schema.Schema{ 94 | "key": &schema.Schema{ 95 | Type: schema.TypeString, 96 | Required: true, 97 | ValidateFunc: validation.StringIsNotWhiteSpace, 98 | Description: "Tag Key", 99 | }, 100 | "value": &schema.Schema{ 101 | Type: schema.TypeString, 102 | Optional: true, 103 | Description: "Tag Value", 104 | }, 105 | }, 106 | }, 107 | }, 108 | } 109 | 110 | // Delay schema 111 | var itemDelaySchema = map[string]*schema.Schema{ 112 | "delay": &schema.Schema{ 113 | Type: schema.TypeString, 114 | Optional: true, 115 | ValidateFunc: validation.StringIsNotWhiteSpace, 116 | Default: "1m", 117 | Description: "Item Delay period", 118 | }, 119 | } 120 | 121 | // Interface schema 122 | var itemInterfaceSchema = map[string]*schema.Schema{ 123 | "interfaceid": &schema.Schema{ 124 | Type: schema.TypeString, 125 | Optional: true, 126 | Description: "Host Interface ID", 127 | Default: "0", 128 | }, 129 | } 130 | 131 | // Prototype schema 132 | var itemPrototypeSchema = map[string]*schema.Schema{ 133 | "ruleid": &schema.Schema{ 134 | Type: schema.TypeString, 135 | Required: true, 136 | ForceNew: true, 137 | ValidateFunc: validation.StringIsNotWhiteSpace, 138 | Description: "LLD Rule ID", 139 | }, 140 | } 141 | 142 | // Schema for preprocessor blocks 143 | var itemPreprocessorSchema = &schema.Schema{ 144 | Type: schema.TypeList, 145 | Optional: true, 146 | Elem: &schema.Resource{ 147 | Schema: map[string]*schema.Schema{ 148 | "id": &schema.Schema{ 149 | Type: schema.TypeString, 150 | Computed: true, 151 | }, 152 | "type": &schema.Schema{ 153 | Type: schema.TypeString, 154 | Required: true, 155 | Description: "Preprocessor type, zabbix identifier number", 156 | ValidateFunc: validation.StringMatch(regexp.MustCompile("^[0-9]+$"), "must be numeric"), 157 | }, 158 | "params": &schema.Schema{ 159 | Type: schema.TypeList, 160 | Elem: &schema.Schema{ 161 | Type: schema.TypeString, 162 | ValidateFunc: validation.StringIsNotWhiteSpace, 163 | }, 164 | Optional: true, 165 | Description: "Preprocessor parameters", 166 | }, 167 | "error_handler": &schema.Schema{ 168 | Type: schema.TypeString, 169 | Optional: true, 170 | Default: "", 171 | }, 172 | "error_handler_params": &schema.Schema{ 173 | Type: schema.TypeString, 174 | Optional: true, 175 | Default: "", 176 | }, 177 | }, 178 | }, 179 | } 180 | 181 | // Function signature for context manipulation 182 | type ItemHandler func(*schema.ResourceData, interface{}, *zabbix.Item) 183 | 184 | // return a terraform CreateFunc 185 | func itemGetCreateWrapper(c ItemHandler, r ItemHandler) schema.CreateFunc { 186 | return func(d *schema.ResourceData, m interface{}) error { 187 | return resourceItemCreate(d, m, c, r, false) 188 | } 189 | } 190 | func protoItemGetCreateWrapper(c ItemHandler, r ItemHandler) schema.CreateFunc { 191 | return func(d *schema.ResourceData, m interface{}) error { 192 | return resourceItemCreate(d, m, c, r, true) 193 | } 194 | } 195 | 196 | // return a terraform UpdateFunc 197 | func itemGetUpdateWrapper(c ItemHandler, r ItemHandler) schema.UpdateFunc { 198 | return func(d *schema.ResourceData, m interface{}) error { 199 | return resourceItemUpdate(d, m, c, r, false) 200 | } 201 | } 202 | func protoItemGetUpdateWrapper(c ItemHandler, r ItemHandler) schema.UpdateFunc { 203 | return func(d *schema.ResourceData, m interface{}) error { 204 | return resourceItemUpdate(d, m, c, r, true) 205 | } 206 | } 207 | 208 | // return a terraform ReadFunc 209 | func itemGetReadWrapper(r ItemHandler) schema.ReadFunc { 210 | return func(d *schema.ResourceData, m interface{}) error { 211 | return resourceItemRead(d, m, r, false) 212 | } 213 | } 214 | func protoItemGetReadWrapper(r ItemHandler) schema.ReadFunc { 215 | return func(d *schema.ResourceData, m interface{}) error { 216 | return resourceItemRead(d, m, r, true) 217 | } 218 | } 219 | 220 | // Create Item Resource Handler 221 | func resourceItemCreate(d *schema.ResourceData, m interface{}, c ItemHandler, r ItemHandler, prototype bool) error { 222 | api := m.(*zabbix.API) 223 | 224 | item := buildItemObject(d, api, prototype) 225 | 226 | // run custom function 227 | c(d, m, item) 228 | 229 | log.Trace("preparing item object for create/update: %#v", item) 230 | 231 | items := []zabbix.Item{*item} 232 | 233 | var err error 234 | 235 | if prototype { 236 | err = api.ProtoItemsCreate(items) 237 | } else { 238 | err = api.ItemsCreate(items) 239 | } 240 | 241 | if err != nil { 242 | return err 243 | } 244 | 245 | log.Trace("created item: %+v", items[0]) 246 | 247 | d.SetId(items[0].ItemID) 248 | 249 | return resourceItemRead(d, m, r, prototype) 250 | } 251 | 252 | // Update Item Resource Handler 253 | func resourceItemUpdate(d *schema.ResourceData, m interface{}, c ItemHandler, r ItemHandler, prototype bool) error { 254 | api := m.(*zabbix.API) 255 | 256 | item := buildItemObject(d, api, prototype) 257 | item.ItemID = d.Id() 258 | 259 | // run custom function 260 | c(d, m, item) 261 | 262 | log.Trace("preparing item object for create/update: %#v", item) 263 | 264 | items := []zabbix.Item{*item} 265 | 266 | var err error 267 | 268 | if prototype { 269 | err = api.ProtoItemsUpdate(items) 270 | } else { 271 | err = api.ItemsUpdate(items) 272 | } 273 | 274 | if err != nil { 275 | return err 276 | } 277 | 278 | return resourceItemRead(d, m, r, prototype) 279 | } 280 | 281 | // Read Item Resource Handler 282 | func resourceItemRead(d *schema.ResourceData, m interface{}, r ItemHandler, prototype bool) error { 283 | api := m.(*zabbix.API) 284 | 285 | log.Debug("Lookup of item with id %s", d.Id()) 286 | 287 | var items zabbix.Items 288 | var err error 289 | 290 | params := zabbix.Params{ 291 | "itemids": []string{d.Id()}, 292 | "selectPreprocessing": "extend", 293 | "selectApplications": "extend", 294 | "selectTags": "extend", 295 | } 296 | 297 | if prototype { 298 | params["selectDiscoveryRule"] = "extend" 299 | items, err = api.ProtoItemsGet(params) 300 | } else { 301 | items, err = api.ItemsGet(params) 302 | } 303 | 304 | if err != nil { 305 | return err 306 | } 307 | 308 | if len(items) < 1 { 309 | d.SetId("") 310 | return nil 311 | } 312 | if len(items) > 1 { 313 | return errors.New("multiple items found") 314 | } 315 | item := items[0] 316 | 317 | log.Debug("Got item: %+v", item) 318 | 319 | d.SetId(item.ItemID) 320 | d.Set("hostid", item.HostID) 321 | d.Set("key", item.Key) 322 | d.Set("name", item.Name) 323 | d.Set("history", item.History) 324 | d.Set("trends", item.Trends) 325 | d.Set("valuetype", ITEM_VALUE_TYPES_REV[item.ValueType]) 326 | d.Set("preprocessor", flattenItemPreprocessors(item)) 327 | if prototype && item.DiscoveryRule != nil { 328 | d.Set("ruleid", item.DiscoveryRule.ItemID) 329 | } 330 | 331 | applicationSet := schema.NewSet(schema.HashString, []interface{}{}) 332 | for _, v := range item.Applications { 333 | applicationSet.Add(v) 334 | } 335 | d.Set("applications", applicationSet) 336 | d.Set("tag", flattenTags(item.Tags)) 337 | 338 | // run custom 339 | r(d, m, &item) 340 | 341 | return nil 342 | } 343 | 344 | // Build the base Item Object 345 | func buildItemObject(d *schema.ResourceData, api *zabbix.API, prototype bool) *zabbix.Item { 346 | item := zabbix.Item{ 347 | Key: d.Get("key").(string), 348 | HostID: d.Get("hostid").(string), 349 | Name: d.Get("name").(string), 350 | History: d.Get("history").(string), 351 | Trends: d.Get("trends").(string), 352 | ValueType: ITEM_VALUE_TYPES[d.Get("valuetype").(string)], 353 | } 354 | item.Preprocessors = itemGeneratePreprocessors(d) 355 | apps := d.Get("applications").(*schema.Set).List() 356 | lst := []string{} 357 | for _, a := range apps { 358 | lst = append(lst, a.(string)) 359 | } 360 | item.Applications = lst 361 | item.Tags = tagGenerate(d) 362 | 363 | if v, ok := d.GetOk("trends"); ok { 364 | item.Trends = v.(string) 365 | } else { 366 | if api.Config.Version >= 50400 && 367 | (item.ValueType == zabbix.Text || 368 | item.ValueType == zabbix.Log) { 369 | item.Trends = "0" 370 | } else { 371 | item.Trends = "365d" 372 | } 373 | d.Set("trends", item.Trends) 374 | } 375 | 376 | if prototype { 377 | item.RuleID = d.Get("ruleid").(string) 378 | } 379 | 380 | return &item 381 | } 382 | 383 | // Generate preprocessor objects 384 | func itemGeneratePreprocessors(d *schema.ResourceData) (preprocessors zabbix.Preprocessors) { 385 | preprocessorCount := d.Get("preprocessor.#").(int) 386 | preprocessors = make(zabbix.Preprocessors, preprocessorCount) 387 | 388 | for i := 0; i < preprocessorCount; i++ { 389 | prefix := fmt.Sprintf("preprocessor.%d.", i) 390 | params := d.Get(prefix + "params").([]interface{}) 391 | pstrarr := make([]string, len(params)) 392 | for i := 0; i < len(params); i++ { 393 | pstrarr[i] = params[i].(string) 394 | } 395 | 396 | preprocessors[i] = zabbix.Preprocessor{ 397 | Type: d.Get(prefix + "type").(string), 398 | Params: strings.Join(pstrarr, "\n"), 399 | ErrorHandler: d.Get(prefix + "error_handler").(string), 400 | ErrorHandlerParams: d.Get(prefix + "error_handler_params").(string), 401 | } 402 | } 403 | 404 | return 405 | } 406 | 407 | // Generate terraform flattened form of item preprocessors 408 | func flattenItemPreprocessors(item zabbix.Item) []interface{} { 409 | val := make([]interface{}, len(item.Preprocessors)) 410 | for i := 0; i < len(item.Preprocessors); i++ { 411 | val[i] = map[string]interface{}{ 412 | //"id": host.Interfaces[i].InterfaceID, 413 | "type": item.Preprocessors[i].Type, 414 | "error_handler": item.Preprocessors[i].ErrorHandler, 415 | "error_handler_params": item.Preprocessors[i].ErrorHandlerParams, 416 | } 417 | if item.Preprocessors[i].Params != "" { 418 | val[i].(map[string]interface{})["params"] = strings.Split(item.Preprocessors[i].Params, "\n") 419 | } 420 | } 421 | return val 422 | } 423 | 424 | // Delete Item Resource Handler 425 | func resourceItemDelete(d *schema.ResourceData, m interface{}) error { 426 | api := m.(*zabbix.API) 427 | return api.ItemsDeleteByIds([]string{d.Id()}) 428 | } 429 | func resourceProtoItemDelete(d *schema.ResourceData, m interface{}) error { 430 | api := m.(*zabbix.API) 431 | return api.ProtoItemsDeleteByIds([]string{d.Id()}) 432 | } 433 | -------------------------------------------------------------------------------- /provider/common_lld.go: -------------------------------------------------------------------------------- 1 | package provider 2 | 3 | import ( 4 | "errors" 5 | "fmt" 6 | "regexp" 7 | "strings" 8 | 9 | "github.com/hashicorp/terraform-plugin-sdk/helper/schema" 10 | "github.com/hashicorp/terraform-plugin-sdk/helper/validation" 11 | "github.com/hashicorp/terraform/helper/hashcode" 12 | "github.com/tpretz/go-zabbix-api" 13 | ) 14 | 15 | // eval type 16 | var LLD_EVALTYPE = map[string]zabbix.LLDEvalType{ 17 | "andor": zabbix.LLDAndOr, 18 | "and": zabbix.LLDAnd, 19 | "or": zabbix.LLDOr, 20 | "custom": zabbix.LLDCustom, 21 | } 22 | var LLD_EVALTYPE_REV = map[zabbix.LLDEvalType]string{} 23 | var LLD_EVALTYPE_ARR = []string{} 24 | 25 | // generate the above structures 26 | var _ = func() bool { 27 | for k, v := range LLD_EVALTYPE { 28 | LLD_EVALTYPE_REV[v] = k 29 | LLD_EVALTYPE_ARR = append(LLD_EVALTYPE_ARR, k) 30 | } 31 | return false 32 | }() 33 | 34 | // operator 35 | var LLD_OPERATOR = map[string]zabbix.LLDOperatorType{ 36 | "match": zabbix.LLDMatch, 37 | "notmatch": zabbix.LLDNotMatch, 38 | } 39 | 40 | var LLD_OPERATOR_REV = map[zabbix.LLDOperatorType]string{} 41 | var LLD_OPERATOR_ARR = []string{} 42 | 43 | // generate the above structures 44 | var _ = func() bool { 45 | for k, v := range LLD_OPERATOR { 46 | LLD_OPERATOR_REV[v] = k 47 | LLD_OPERATOR_ARR = append(LLD_OPERATOR_ARR, k) 48 | } 49 | return false 50 | }() 51 | 52 | // common schema elements for all lld types 53 | var lldCommonSchema = map[string]*schema.Schema{ 54 | "hostid": &schema.Schema{ 55 | Type: schema.TypeString, 56 | Required: true, 57 | ForceNew: true, 58 | Description: "Host ID", 59 | ValidateFunc: validation.StringMatch(regexp.MustCompile("^[0-9]+$"), "must be numeric"), 60 | }, 61 | "delay": &schema.Schema{ 62 | Type: schema.TypeString, 63 | Optional: true, 64 | ValidateFunc: validation.StringIsNotWhiteSpace, 65 | Default: "3600", 66 | Description: "LLD Delay period", 67 | }, 68 | "lifetime": &schema.Schema{ 69 | Type: schema.TypeString, 70 | Optional: true, 71 | ValidateFunc: validation.StringIsNotWhiteSpace, 72 | Default: "30d", 73 | Description: "LLD Stale Item Lifetime", 74 | }, 75 | "key": &schema.Schema{ 76 | Type: schema.TypeString, 77 | Description: "LLD KEY", 78 | ValidateFunc: validation.StringIsNotWhiteSpace, 79 | Required: true, 80 | }, 81 | "name": &schema.Schema{ 82 | Type: schema.TypeString, 83 | Description: "LLD Name", 84 | ValidateFunc: validation.StringIsNotWhiteSpace, 85 | Required: true, 86 | }, 87 | "preprocessor": lldPreprocessorSchema, 88 | "condition": lldFilterConditionSchema, 89 | "macro": lldMacroPathSchema, 90 | "evaltype": &schema.Schema{ 91 | Type: schema.TypeString, 92 | Description: "EvalType, one of: " + strings.Join(LLD_EVALTYPE_ARR, ", "), 93 | ValidateFunc: validation.StringInSlice(LLD_EVALTYPE_ARR, false), 94 | Default: "andor", 95 | Optional: true, 96 | }, 97 | "formula": &schema.Schema{ 98 | Type: schema.TypeString, 99 | Description: "Formula", 100 | Default: "", 101 | Optional: true, 102 | }, 103 | } 104 | 105 | // Interface schema 106 | var lldInterfaceSchema = map[string]*schema.Schema{ 107 | "interfaceid": &schema.Schema{ 108 | Type: schema.TypeString, 109 | Optional: true, 110 | Description: "Host Interface ID", 111 | Default: "0", 112 | }, 113 | } 114 | 115 | // Schema for preprocessor blocks 116 | var lldPreprocessorSchema = &schema.Schema{ 117 | Type: schema.TypeList, 118 | Optional: true, 119 | Elem: &schema.Resource{ 120 | Schema: map[string]*schema.Schema{ 121 | "id": &schema.Schema{ 122 | Type: schema.TypeString, 123 | Computed: true, 124 | }, 125 | "type": &schema.Schema{ 126 | Type: schema.TypeString, 127 | Required: true, 128 | Description: "Preprocessor type, zabbix identifier number", 129 | ValidateFunc: validation.StringMatch(regexp.MustCompile("^[0-9]+$"), "must be numeric"), 130 | }, 131 | "params": &schema.Schema{ 132 | Type: schema.TypeList, 133 | Elem: &schema.Schema{ 134 | Type: schema.TypeString, 135 | ValidateFunc: validation.StringIsNotWhiteSpace, 136 | }, 137 | Optional: true, 138 | Description: "Preprocessor parameters", 139 | }, 140 | "error_handler": &schema.Schema{ 141 | Type: schema.TypeString, 142 | Optional: true, 143 | Default: "", 144 | }, 145 | "error_handler_params": &schema.Schema{ 146 | Type: schema.TypeString, 147 | Optional: true, 148 | Default: "", 149 | }, 150 | }, 151 | }, 152 | } 153 | 154 | var lldValidationMacro = validation.StringMatch(regexp.MustCompile("^\\{#[A-Z][A-Z._]*\\}$"), "must be a LLD macro format") 155 | 156 | var lldMacroPathSchema = &schema.Schema{ 157 | Type: schema.TypeSet, 158 | Optional: true, 159 | Elem: &schema.Resource{ 160 | Schema: map[string]*schema.Schema{ 161 | "macro": &schema.Schema{ 162 | Type: schema.TypeString, 163 | Required: true, 164 | Description: "Macro", 165 | ValidateFunc: lldValidationMacro, 166 | }, 167 | "path": &schema.Schema{ 168 | Type: schema.TypeString, 169 | Required: true, 170 | Description: "Macro Path", 171 | ValidateFunc: validation.StringMatch(regexp.MustCompile("^\\$"), "must be a json path"), 172 | }, 173 | }, 174 | }, 175 | } 176 | 177 | // Schema for filter block 178 | var lldFilterConditionSchema = &schema.Schema{ 179 | Type: schema.TypeList, 180 | Optional: true, 181 | Elem: &schema.Resource{ 182 | Schema: map[string]*schema.Schema{ 183 | "id": &schema.Schema{ 184 | Type: schema.TypeString, 185 | Computed: true, 186 | }, 187 | "macro": &schema.Schema{ 188 | Type: schema.TypeString, 189 | Required: true, 190 | Description: "Filter Macro", 191 | ValidateFunc: lldValidationMacro, 192 | }, 193 | "value": &schema.Schema{ 194 | Type: schema.TypeString, 195 | Required: true, 196 | Description: "Filter Value", 197 | ValidateFunc: validation.StringIsNotWhiteSpace, 198 | }, 199 | "operator": &schema.Schema{ 200 | Type: schema.TypeString, 201 | Optional: true, 202 | Default: "match", 203 | Description: "Operator, one of: " + strings.Join(LLD_OPERATOR_ARR, ", "), 204 | ValidateFunc: validation.StringInSlice(LLD_OPERATOR_ARR, false), 205 | }, 206 | }, 207 | }, 208 | } 209 | 210 | // Function signature for context manipulation 211 | type LLDHandler func(*schema.ResourceData, interface{}, *zabbix.LLDRule) 212 | 213 | // return a terraform CreateFunc 214 | func lldGetCreateWrapper(c LLDHandler, r LLDHandler) schema.CreateFunc { 215 | return func(d *schema.ResourceData, m interface{}) error { 216 | return resourceLLDCreate(d, m, c, r) 217 | } 218 | } 219 | 220 | // return a terraform UpdateFunc 221 | func lldGetUpdateWrapper(c LLDHandler, r LLDHandler) schema.UpdateFunc { 222 | return func(d *schema.ResourceData, m interface{}) error { 223 | return resourceLLDUpdate(d, m, c, r) 224 | } 225 | } 226 | 227 | // return a terraform ReadFunc 228 | func lldGetReadWrapper(r LLDHandler) schema.ReadFunc { 229 | return func(d *schema.ResourceData, m interface{}) error { 230 | return resourceLLDRead(d, m, r) 231 | } 232 | } 233 | 234 | // Create lld Resource Handler 235 | func resourceLLDCreate(d *schema.ResourceData, m interface{}, c LLDHandler, r LLDHandler) error { 236 | api := m.(*zabbix.API) 237 | 238 | lld := buildLLDObject(d) 239 | 240 | // run custom function 241 | c(d, m, lld) 242 | 243 | log.Trace("preparing lld object for create/update: %#v", lld) 244 | 245 | llds := []zabbix.LLDRule{*lld} 246 | 247 | err := api.LLDsCreate(llds) 248 | 249 | if err != nil { 250 | return err 251 | } 252 | 253 | log.Trace("created lld: %+v", llds[0]) 254 | 255 | d.SetId(llds[0].ItemID) 256 | 257 | return resourceLLDRead(d, m, r) 258 | } 259 | 260 | // Update lld Resource Handler 261 | func resourceLLDUpdate(d *schema.ResourceData, m interface{}, c LLDHandler, r LLDHandler) error { 262 | api := m.(*zabbix.API) 263 | 264 | lld := buildLLDObject(d) 265 | lld.ItemID = d.Id() 266 | 267 | // run custom function 268 | c(d, m, lld) 269 | 270 | log.Trace("preparing lld object for create/update: %#v", lld) 271 | 272 | llds := []zabbix.LLDRule{*lld} 273 | 274 | err := api.LLDsUpdate(llds) 275 | 276 | if err != nil { 277 | return err 278 | } 279 | 280 | return resourceLLDRead(d, m, r) 281 | } 282 | 283 | // Read lld Resource Handler 284 | func resourceLLDRead(d *schema.ResourceData, m interface{}, r LLDHandler) error { 285 | api := m.(*zabbix.API) 286 | 287 | log.Debug("Lookup of lld with id %s", d.Id()) 288 | 289 | llds, err := api.LLDsGet(zabbix.Params{ 290 | "itemids": []string{d.Id()}, 291 | "selectPreprocessing": "extend", 292 | "selectLLDMacroPaths": "extend", 293 | "selectFilter": "extend", 294 | }) 295 | 296 | if err != nil { 297 | return err 298 | } 299 | 300 | if len(llds) < 1 { 301 | d.SetId("") 302 | return nil 303 | } 304 | if len(llds) > 1 { 305 | return errors.New("multiple llds found") 306 | } 307 | lld := llds[0] 308 | 309 | log.Debug("Got lld: %+v", lld) 310 | 311 | d.SetId(lld.ItemID) 312 | d.Set("hostid", lld.HostID) 313 | d.Set("key", lld.Key) 314 | d.Set("name", lld.Name) 315 | d.Set("delay", lld.Delay) 316 | d.Set("lifetime", lld.LifeTime) 317 | d.Set("evaltype", LLD_EVALTYPE_REV[lld.Filter.EvalType]) 318 | d.Set("formula", lld.Filter.Formula) 319 | d.Set("condition", flattenlldConditions(lld)) 320 | d.Set("preprocessor", flattenlldPreprocessors(lld)) 321 | d.Set("macro", flattenlldMacroPaths(lld)) 322 | 323 | // run custom 324 | r(d, m, &lld) 325 | 326 | return nil 327 | } 328 | 329 | // Build the base lld Object 330 | func buildLLDObject(d *schema.ResourceData) *zabbix.LLDRule { 331 | lld := zabbix.LLDRule{ 332 | Key: d.Get("key").(string), 333 | HostID: d.Get("hostid").(string), 334 | Name: d.Get("name").(string), 335 | Delay: d.Get("delay").(string), 336 | LifeTime: d.Get("lifetime").(string), 337 | } 338 | 339 | lld.Preprocessors = lldGeneratePreprocessors(d) 340 | lld.MacroPaths = lldGenerateMacroPaths(d) 341 | 342 | lld.Filter.EvalType = LLD_EVALTYPE[d.Get("evaltype").(string)] 343 | lld.Filter.Formula = d.Get("formula").(string) 344 | lld.Filter.Conditions = lldGenerateConditions(d) 345 | 346 | return &lld 347 | } 348 | 349 | // Generate preprocessor objects 350 | func lldGeneratePreprocessors(d *schema.ResourceData) (preprocessors zabbix.Preprocessors) { 351 | preprocessorCount := d.Get("preprocessor.#").(int) 352 | preprocessors = make(zabbix.Preprocessors, preprocessorCount) 353 | 354 | for i := 0; i < preprocessorCount; i++ { 355 | prefix := fmt.Sprintf("preprocessor.%d.", i) 356 | params := d.Get(prefix + "params").([]interface{}) 357 | pstrarr := make([]string, len(params)) 358 | for i := 0; i < len(params); i++ { 359 | pstrarr[i] = params[i].(string) 360 | } 361 | 362 | preprocessors[i] = zabbix.Preprocessor{ 363 | Type: d.Get(prefix + "type").(string), 364 | Params: strings.Join(pstrarr, "\n"), 365 | ErrorHandler: d.Get(prefix + "error_handler").(string), 366 | ErrorHandlerParams: d.Get(prefix + "error_handler_params").(string), 367 | } 368 | } 369 | 370 | return 371 | } 372 | 373 | // Generate macro path objects 374 | func lldGenerateMacroPaths(d *schema.ResourceData) (paths zabbix.LLDMacroPaths) { 375 | set := d.Get("macro").(*schema.Set).List() 376 | paths = make(zabbix.LLDMacroPaths, len(set)) 377 | 378 | for i := 0; i < len(paths); i++ { 379 | current := set[i].(map[string]interface{}) 380 | paths[i] = zabbix.LLDMacroPath{ 381 | Macro: current["macro"].(string), 382 | Path: current["path"].(string), 383 | } 384 | } 385 | 386 | return 387 | } 388 | 389 | // Generate LLD Filter Conditions 390 | func lldGenerateConditions(d *schema.ResourceData) (conditions zabbix.LLDRuleFilterConditions) { 391 | conditionsCount := d.Get("condition.#").(int) 392 | conditions = make(zabbix.LLDRuleFilterConditions, conditionsCount) 393 | 394 | for i := 0; i < conditionsCount; i++ { 395 | prefix := fmt.Sprintf("condition.%d.", i) 396 | 397 | conditions[i] = zabbix.LLDRuleFilterCondition{ 398 | Macro: d.Get(prefix + "macro").(string), 399 | Value: d.Get(prefix + "value").(string), 400 | Operator: LLD_OPERATOR[d.Get(prefix+"operator").(string)], 401 | } 402 | id := d.Get(prefix + "id").(string) 403 | if id != "" { 404 | conditions[i].FormulaID = id 405 | } 406 | } 407 | 408 | return 409 | } 410 | 411 | // Generate terraform flattened form of lld preprocessors 412 | func flattenlldPreprocessors(lld zabbix.LLDRule) []interface{} { 413 | val := make([]interface{}, len(lld.Preprocessors)) 414 | for i := 0; i < len(lld.Preprocessors); i++ { 415 | parr := strings.Split(lld.Preprocessors[i].Params, "\n") 416 | val[i] = map[string]interface{}{ 417 | //"id": host.Interfaces[i].InterfaceID, 418 | "type": lld.Preprocessors[i].Type, 419 | "params": parr, 420 | "error_handler": lld.Preprocessors[i].ErrorHandler, 421 | "error_handler_params": lld.Preprocessors[i].ErrorHandlerParams, 422 | } 423 | } 424 | return val 425 | } 426 | 427 | func flattenlldMacroPaths(lld zabbix.LLDRule) *schema.Set { 428 | set := schema.NewSet(func(i interface{}) int { 429 | m := i.(map[string]interface{}) 430 | return hashcode.String(m["macro"].(string) + "P" + m["path"].(string)) 431 | }, []interface{}{}) 432 | for i := 0; i < len(lld.MacroPaths); i++ { 433 | set.Add(map[string]interface{}{ 434 | "macro": lld.MacroPaths[i].Macro, 435 | "path": lld.MacroPaths[i].Path, 436 | }) 437 | } 438 | return set 439 | } 440 | 441 | // Generate terraform flattened form of lld filter conditions 442 | func flattenlldConditions(lld zabbix.LLDRule) []interface{} { 443 | val := make([]interface{}, len(lld.Filter.Conditions)) 444 | for i := 0; i < len(lld.Filter.Conditions); i++ { 445 | val[i] = map[string]interface{}{ 446 | "id": lld.Filter.Conditions[i].FormulaID, 447 | "macro": lld.Filter.Conditions[i].Macro, 448 | "value": lld.Filter.Conditions[i].Value, 449 | "operator": LLD_OPERATOR_REV[lld.Filter.Conditions[i].Operator], 450 | } 451 | } 452 | return val 453 | } 454 | 455 | // Delete lld Resource Handler 456 | func resourceLLDDelete(d *schema.ResourceData, m interface{}) error { 457 | api := m.(*zabbix.API) 458 | return api.LLDDeleteByIds([]string{d.Id()}) 459 | } 460 | --------------------------------------------------------------------------------