1<a id="Service-apply-for-example"></a>Working with Apply for rules - tcp ports example 2============================================== 3 4This example wants to show you how to make use of `Apply For` rule for services. 5 6First you need to define a `tcp_ports` data field of type `Array` assigned to a `Host Template`. 7Refer to [Working with fields](14-Fields-example-interfaces-array.md) section to setup a data field. 8You also need to define a `tcp_port` data field of type `String`, we will associate it to a 9`Service Template` later. 10 11Then, please go to the `Dashboard` and choose the `Monitored services` dashlet: 12 13![Dashboard - Monitored services](screenshot/director/15_apply-for-services/151_monitored_services.png) 14 15Then create a new `Service template` with check command `tcp`: 16 17![Define service template - tcp](screenshot/director/15_apply-for-services/152_add_service_template.png) 18 19Then associate the data field `tcp_port` to this `Service template`: 20 21![Associate field to service template - tcp_port](screenshot/director/15_apply-for-services/153_add_service_template_field.png) 22 23Then create a new `apply-rule` for the `Service template`: 24 25![Define apply rule](screenshot/director/15_apply-for-services/154_create_apply_rule.png) 26 27Now define the `Apply For` property, select the previously defined field `tcp_ports` associated to 28the host template. `Apply For` rule define a variable `config` that can be used as `$config$`, it 29corresponds to the item of the array it will iterate on. 30 31Set the `Tcp port` property to `$config$`: 32 33![Add field to template](screenshot/director/15_apply-for-services/155_configure_apply_for.png) 34 35(Side note: if you can't see your `tcp_ports` property in `Apply For` dropdown, try to create one 36host with a non-empty `tcp_ports` value.) 37 38That's it, now all your hosts defining a `tcp_ports` variable will be assigned the `Tcp Check` 39service. 40 41Have a look at the config preview, it will show you how `Apply For` services will look like once 42deployed: 43 44![Host config preview with Array](screenshot/director/15_apply-for-services/156_config_preview.png) 45