24 ports? Why 24? It seems to me, that you should only be concerned about the network and any major hosts/servers that are online 24/7. If in fact, you have a switch with all 24 ports being used as trunks and for important servers(24/7) then ok. But not for some user host that is powered up/down several times/day.
Anyway, yes, use the template directive and only define directives in the template that will be used for every single service. You will have to define a service for each and every host(port 1-24). Each service will use the default template and will have 2 or 3 lines that will be additional.
name remote-nagios ; The ‘name’ of this service template, referenced in other service definitions
passive_checks_enabled 1 ; Passive service checks are enabledpaccepted
parallelize_check 1 ; Active service checks should be parallelized (disabling this can lead to major performance problems)
obsess_over_service 0 ; We should obsess over this service (if necessary)
freshness_threshold 1200 ; Default is 0 which automatically determines threshold
notifications_enabled 0 ; Service notifications are enabled
event_handler_enabled 0 ; Service event handler is enabled
flap_detection_enabled 0 ; Flap detection is enabled
process_perf_data 0 ; Process performance data
retain_status_information 1 ; Retain status information across program restarts
retain_nonstatus_information 1 ; Retain non-status information across program restarts
register 0 ; DONT REGISTER THIS DEFINITION - ITS NOT A REAL SERVICE, JUST A TEMPLATE!
So, there is really no way around it. I have to have a few of these that are unique, like:
check_command #NOTE, my command is commented out, since the check command is being ran remotely and output sent via nsca.
servicegroups #may or may not have to be unique
process_perf_data may or may not have to be unique
So, at the least, you have to have 4 directives defined for each service.
check_command #depends on if it’s a passive or active check
FYI, it’s not the same service, so get that out of your head. Each port on the switch that is important enough to monitor, is important enough to have a service defined for that port only. Remember, this port on the switch is actually a nagios hostname. So that one hostname can have many services for it. i.e. traffic_in_out, ifOperstatus, stp_status(spanning tree status) duplex, etc, etc,
Get fancy too, if you have vlans or mlt’s setup.
For example, in your status map/hosts.cfg
switch-A connects to VLAN-A which connects to switch-A-1p24 and also switch-A-2p24.
switch-A-1p24 connects to server-A-eth0
switch-A-2p24 connects to Router-A-if4
server-A-eth0 connects to Server-A
Router-A-if4 connects to Router-A
Now, your status map looks great. Go ahead and unplug all the cables from that section of network, and from your nagios status map, you can plug everything back in, just like it was before.
PS:, watch out, some switches don’t have the ports numbered 1-whatever, especially when it’s a stack of switches.
So, for a 2 unit stack you might think they will be 1-48, but I’ll bet they are not 1-48. Double check by using your mib browser (mbrowse).