Eėn van de meest gebruikte functies van Puppet is controleren of bestanden gewijzigd worden. Dit kan een bewuste wijziging zijn maar het zou ook kunnen dat er kwaadwillende bedoelingen achter schuilen. In een Linux omgeving kan het verstandig zijn om het bestand /etc/passwd in de gaten te houden en als er wijzigingen aan dit bestand worden gemaakt willen we dat weten. Er zijn diverse attributen van een bestand die gemonitored kunnen worden:
Attribute | Purpose |
content | This is the md5sum checksum of the content. This changes whenever the file content changes. |
ctime | This denotes the creation time of the file per the Unix operating system’s stat system call. |
ensure | This contains the type of file, directory, or link if managed by Puppet. |
group | This denotes the Unix group of the file. |
mode | This is the file’s Unix mode. |
mtime | This denotes the last modification of the file per the Unix operating system’s stat system call. |
owner | This denotes the Unix user who owns the file. |
selrange | This denotes the SELinux range component of the file on systems supporting SELinux. |
selrole | This denotes the SELinux role of the file on systems supporting SELinux. |
seltype | This denotes the SELinux type of the file for systems supporting SELinux. |
seluser | This denotes the SELinux user of the file for systems supporting SELinux. |
type | This contains the type of the file—typically, the same as ensure if managed. |
We gaan nu het manifest voor de MusicPlayers aanpassen en het bestand /etc/passwd in de gaten houden. We doen dit door het manifest bestand aan te passen waardoor deze er voor de node huiskamer.digitalinfo.local er zo uit gaat zien:
node 'huiskamer.digitalinfo.local' { class { 'musicplayer::motd': } class { 'musicplayer::auth_keys': } file { '/etc/passwd': audit => 'all', } }
De regel met ‘audit => ‘all” zal dus alle attributen van het bestand gaan monitoren en als we op de node een ‘sudo puppet agent -t‘ doen zullen deze attributen opgenomen worden:
Als nu het bestand /etc/passwd gewijzigd wordt gaan we dat zien.
Op de node gaan we een gebruiker toevoegen:
sudo useradd testuser
en hierna gaan we puppet nogmaals runnen
sudo puppet agent -t
De uitvoer hiervan is:
We zien hier dat de ‘content‘, de ‘ctime‘ en de ‘mtime‘ attributen gewijzigd zijn te opzichte van de vorige controle.
De puppet-agent zal deze wijzigingen aan het bestand loggen en dat kunnen we ook in de puppet-monitor zien.
Op dezelfde manier als de file-resource kunnen ook andere resources gemonitored worden zoals cron, services, packages, mount, users, etc. Raadpleeg de puppet documentatie voor de verschillende resource types.