= Icinga Hands - On - Cont= Through this hands-on you see * How to add a host * How to add a service * How to check DNS * How to add an agent * How to monitor disk space * How to check files == How to add a host == === How to add a host template === Before adding hosts, the host templates have to be added. These templates should have the details on how host needs to be checked. [[Image(https://ws.learn.ac.lk/raw-attachment/wiki/NSM2021/Agenda/iCinga/host_template28.png, 600)]] === Add a host === Add the hosts after adding host template: [[Image(https://ws.learn.ac.lk/raw-attachment/wiki/NSM2021/Agenda/iCinga/add_hosts30.png, 600)]] == How to add a Service == === How to add a service template === Before adding services, the service templates has to be added, [[Image(https://ws.learn.ac.lk/raw-attachment/wiki/NSM2021/Agenda/iCinga/service_template32.png, 600)]] === Add a Service === After, services can be added as following as per requirements: [[Image(https://ws.learn.ac.lk/raw-attachment/wiki/NSM2021/Agenda/iCinga/service33.png, 600)]] === Check DNS === Add the service template to dns check as follows, [[Image(https://ws.learn.ac.lk/raw-attachment/wiki/NSM2021/Agenda/icinga_handson_cont/dns_template.png, 600)]] After, adding the service template, you will see a field when select the service template as in the example below, as Custom fields : dns check [[Image(https://ws.learn.ac.lk/raw-attachment/wiki/NSM2021/Agenda/icinga_handson_cont/fields_dns.png, 600)]] After selecting the fields from dropdown list as per the requirements, add the fields to the service template. [[Image(https://ws.learn.ac.lk/raw-attachment/wiki/NSM2021/Agenda/icinga_handson_cont/dns_fields.png, 600)]] Deploy the changes you made and then you can modify the service template as follows if you need. [[Image(https://ws.learn.ac.lk/raw-attachment/wiki/NSM2021/Agenda/icinga_handson_cont/dns_check3.png, 600)]] Use the DNS service you created as needed. == How to add an Agent== ==== Host template for agents ==== Agent settings are not available for modification directly on a host object. This requires you to create an “Icinga Agent” template. You could name it exactly like that; it’s important to use meaningful names for your templates. For setting up an agent, Host template should be created using iCinga director as follows, `Icinga director > Hosts > Host Templates` Main Properties will be shown as following [[Image(https://ws.learn.ac.lk/raw-attachment/wiki/NSM2021/Agenda/icinga_handson_cont/agent1_host_template.png, 600)]] In the `Icinga agent and zone settings` , Following options should be selected, [[Image(https://ws.learn.ac.lk/raw-attachment/wiki/NSM2021/Agenda/icinga_handson_cont/agent_host_template2.png, 600)]] '''NOTE : You should click deploy pending changes in Activity log section under Icinga Director''' ==== Adding hosts as agents ==== ''Note : Always try to use meaningful names in configurations'' After creating host template for, host can be added as an agent for the system. `Icinga director > Hosts > Host` As following example, the details should be assigned as per the requirement, [[Image(https://ws.learn.ac.lk/raw-attachment/wiki/NSM2021/Agenda/icinga_handson_cont/adding_agent_host.png, 600)]] After apply the deployment, setup preparation for agent has to be done ==== Before Executing the agent scripts... ==== Before executing the agent scripts in the relevant machines, Icinga2 have to be installed in the Agent as following instructions below, {{{ apt-get -y install apt-transport-https wget gnupg wget -O - https://packages.icinga.com/icinga.key | apt-key add - . /etc/os-release; if [ ! -z ${UBUNTU_CODENAME+x} ]; then DIST="${UBUNTU_CODENAME}"; else DIST="$(lsb_release -c| awk '{print $2}')"; fi; echo "deb https://packages.icinga.com/ubuntu icinga-${DIST} main" > /etc/apt/sources.list.d/${DIST}-icinga.list echo "deb-src https://packages.icinga.com/ubuntu icinga-${DIST} main" >> /etc/apt/sources.list.d/${DIST}-icinga.list apt-get update apt-get install icinga2 monitoring-plugins }}} '''Note : Please check the `/etc/hosts` file and verify that the agent is resolving for the Nodename of master node before executing the agent scripts.''' (Otherwise you will not be able to connect agent hosts with a certificate error) `icinga director > hosts > host >`, click on the agent and agent tab contains the scripts for agent manual configurations. Click on the agent host you added and a tab called Agent will be shown as in the following image, [[Image(https://ws.learn.ac.lk/raw-attachment/wiki/NSM2021/Agenda/icinga_handson_cont/agent_scripts.png, 600)]] You will see two scripts to execute on agent hosts. They are for Agent deployment instructions, you will get Windows Kickstart Script and a Linux command line script for the agents as above in the example. Download the required script into the agent hosts and execute the scripts for configurations. (you may copy paste the script content into a file via vim or nano, but do not directly run them on plain console ). Assuming the script file is `icinga-agent.sh` {{{ chmod +x icinga-agent.sh ./icinga-agent.sh }}} After, you need to sign the agent's security certificate by execute following commands on '''master node''' as follow in the example * Find Agent Fingerprint: `icinga2 ca list --all` * Sign Agents Fingerprint: `icinga ca sign ` [[Image(https://ws.learn.ac.lk/raw-attachment/wiki/NSM2021/Agenda/icinga_handson_cont/master_listing_agents.jpeg, 600)]] == How to check disk space == Before adding the service to check the disk space in a host, add the service template for the diskspace with necessary commands as following image [[Image(https://ws.learn.ac.lk/raw-attachment/wiki/NSM2021/Agenda/icinga_handson_cont/diskspace_service.png, 600)]] And after, Please add the service to the host to monitor the diskspace as follows [[Image(https://ws.learn.ac.lk/raw-attachment/wiki/NSM2021/Agenda/icinga_handson_cont/diskcheck1.png, 600)]] [[Image(https://ws.learn.ac.lk/raw-attachment/wiki/NSM2021/Agenda/icinga_handson_cont/diskcheck2.png, 600)]] == How to check files == To monitor files, an example is taken to show how to monitor specific file. A service for has to be created to check the files. As per the example below, create a template for the file checking [[Image(https://ws.learn.ac.lk/raw-attachment/wiki/NSM2021/Agenda/icinga_handson_cont/check_files_template.png, 600)]] And since we have to pass the parameters, We can add the fields after adding the template, [[Image(https://ws.learn.ac.lk/raw-attachment/wiki/NSM2021/Agenda/icinga_handson_cont/adding_fileds_check_fils.png, 600)]] Select the parameters which are needed to be used in the drop down list and after adding the fields, you can change the filed values in custom properties in the service template [[Image(https://ws.learn.ac.lk/raw-attachment/wiki/NSM2021/Agenda/icinga_handson_cont/Change_parameters_checkFiles.png, 600)]] After changing the configurations, Deploy the changes for `Icinga director > activity log`.