Checkmk Agent in einem Home Ordner installieren
Übersetzt aus dem englischen Original.
Damit lässt sich der Checkmk Agent installieren, ohne etwas zu installieren. Nützlich für Appliances.
Inhalt
- Checkmk Agent Installation im Home Ordner (z.B. für Appliances)
- Inhalt
- Grundlagen
- Vorbereitung der Checkmk Regel
- Zugriff aus Checkmk
- Ansible
- Referenz
- Tags
Grundlagen
Seit Checkmk 2.4 unterstützt der Linux Agent eine Variable namens MK_INSTALLDIR. Ist diese Variable gesetzt, werden alle Pfade der Checkmk Dateien wie folgt gesetzt:
- MK_LIBDIR=“${MK_INSTALLDIR}/package“
- MK_CONFDIR=“${MK_INSTALLDIR}/package/config“
- MK_VARDIR=“${MK_INSTALLDIR}/runtime“
- MK_LOGDIR=“${MK_INSTALLDIR}/runtime/log“
- MK_BIN=“${MK_INSTALLDIR}/package/bin“
Eine SSH Command Restriction könnte dann so aussehen:
command="env MK_INSTALLDIR=/home/parallels/cmk/ /home/parallels/cmk/package/bin/check_mk_agent",no-port-forwarding,no-X11-forwarding,no-agent-forwarding,no-pty ssh-ed25519 AAAACmBS bkuhn@MacBook-Pro
Die Basis des Pakets kann in der Agent Bakery konfiguriert werden. Dort sollten auch alle Plugins konfiguriert werden.
Vorbereitung der Checkmk Regel
Verwenden Sie die Regel Customize Agent, um /cmk als Zielpfad zu setzen. Das Ansible Playbook entpackt dann nach /home/user/, wo Sie anschließend den Unterordner cmk haben.
Zugriff aus Checkmk
Setzen Sie das Datenquellenprogramm wie folgt:
ssh $HOSTNAME$ > /dev/null
Eventuell möchten Sie noch den SSH User und den Pfad zum SSH Key ergänzen.
Ansible Playbook zum Hochladen von Tar und SSH Key
Variante, um die Tar Datei hochzuladen und SSH vorzubereiten. Am besten schauen Sie sich aber auch die zweite Version der YML im nächsten Kapitel an.
---
- name: Install and configure CheckMK Agent
hosts: all
vars:
target_user: "parallels"
ssh_key_file: "{{ playbook_dir }}/key.pem"
agent_tar_file: "{{ playbook_dir }}/agent.tar.gz"
agent_install_dir: "/home/{{ target_user }}/cmk"
ssh_command_restriction: >
command="env MK_INSTALLDIR=/home/{{ target_user }}/cmk/ /home/parallels/{{ target_user }}/package/bin/check_mk_agent",
no-port-forwarding,
no-X11-forwarding,
no-agent-forwarding,
no-pty
tasks:
- name: Read SSH public key from file
set_fact:
ssh_public_key: "{{ lookup('file', ssh_key_file) }}"
delegate_to: localhost
- name: Add SSH public key with command restriction
authorized_key:
user: "{{ target_user }}"
state: present
key: "{{ ssh_public_key }}"
key_options: "{{ ssh_command_restriction }}"
comment: "Checkmk Monitoring Agent "
- name: Create installation directory
file:
path: "{{ agent_install_dir }}"
state: directory
owner: "{{ target_user }}"
group: "{{ target_user }}"
mode: '0755'
- name: Copy tar file to target system
copy:
src: "{{ agent_tar_file }}"
dest: "/{{agent_install_dir}}/checkmk-agent.tar.gz"
owner: "{{ target_user }}"
group: "{{ target_user }}"
mode: '0644'
- name: Extract agent tar file
unarchive:
src: "/{{agent_install_dir}}/checkmk-agent.tar.gz"
dest: "{{ agent_install_dir }}"
owner: "{{ target_user }}"
group: "{{ target_user }}"
remote_src: yes
- name: Clean up temporary tar file
file:
path: "/{{agent_install_dir}}/checkmk-agent.tar.gz"
state: absent
Variante ohne SSH Key und mit direktem Agent Download:
Deutlich bessere Version, lädt direkt aus Checkmk herunter, sofern Checkmk erreichbar ist:
---
- hosts: all
gather_facts: false
vars:
cmk_server: cmkmaster.company.de
cmk_server_port: 443
cmk_site: cmkmaster
cmk_user: automation_oracleinstall
cmk_secret: "xxxx"
ansible_user: "svc_Monitoring"
ansible_ssh_private_key_file: local_id_oracle
agent_install_dir: /home/svc_monitoring
agent_internal_path: "{{agent_install_dir}}/cmk-agent" # As Configured for the Agent in CMK (/cmk-agent)
tasks:
- name: Create Wrapper
copy:
content: "env MK_INSTALLDIR={{agent_install_dir}}/ {{agent_internal_path }}/default/package/bin/check_mk_agent"
dest: "{{agent_install_dir}}/agent_wrapper.sh"
owner: "{{ ansible_user }}"
mode: 'u+x'
- name: "Download Checkmk Agent"
ansible.builtin.uri:
url: "https://{{ cmk_server }}:{{cmk_server_port}}/{{ cmk_site }}/check_mk/api/1.0/domain-types/agent/actions/download_by_host/invoke?os_type=linux_tgz&host_name={{ inventory_hostname }}"
dest: "{{ agent_install_dir }}/checkmk-agent.tar.gz"
method: GET
validate_certs: no
headers:
Authorization: "Bearer {{ cmk_user }} {{ cmk_secret }}"
Accept: "application/octet-stream"
- name: Delete files from previous installation
file:
path: "{{agent_internal_path}}"
state: absent
- name: Extract agent tar file
unarchive:
src: "{{agent_install_dir}}/checkmk-agent.tar.gz"
dest: "{{ agent_install_dir }}"
owner: "{{ ansible_user }}"
remote_src: yes
Was Sie brauchen, ist vielleicht eine Mischung aus beiden Varianten. Die zweite ist flexibler und leistungsfähiger, die erste eher „manuell“.