# Mettre en place un service permettant de recueillir ces logs et de pouvoir les consulter (serveur de logs)

### Serveur de logs

#### Infrastructure mise en place

<div class="overflow-x-auto w-full px-2 mb-6" id="bkmrk-composant-d%C3%A9tail-ser"><table class="min-w-full border-collapse text-sm leading-[1.7] whitespace-normal"><thead class="text-left"><tr><th class="text-text-100 border-b-0.5 border-border-300/60 py-2 pr-4 align-top font-bold" scope="col">Composant</th><th class="text-text-100 border-b-0.5 border-border-300/60 py-2 pr-4 align-top font-bold" scope="col">Détail</th></tr></thead><tbody><tr><td class="border-b-0.5 border-border-300/30 py-2 pr-4 align-top">Serveur</td><td class="border-b-0.5 border-border-300/30 py-2 pr-4 align-top">VM ubuntu test ProXmox</td></tr><tr><td class="border-b-0.5 border-border-300/30 py-2 pr-4 align-top">IP</td><td class="border-b-0.5 border-border-300/30 py-2 pr-4 align-top">192.168.99.7</td></tr><tr><td class="border-b-0.5 border-border-300/30 py-2 pr-4 align-top">OS</td><td class="border-b-0.5 border-border-300/30 py-2 pr-4 align-top">Ubuntu 22.04.5 LTS</td></tr><tr><td class="border-b-0.5 border-border-300/30 py-2 pr-4 align-top">Service de collecte</td><td class="border-b-0.5 border-border-300/30 py-2 pr-4 align-top">rsyslog 8.2112.0</td></tr><tr><td class="border-b-0.5 border-border-300/30 py-2 pr-4 align-top">Interface web</td><td class="border-b-0.5 border-border-300/30 py-2 pr-4 align-top">Loganalyzer 4.1.13</td></tr><tr><td class="border-b-0.5 border-border-300/30 py-2 pr-4 align-top">Port d'écoute</td><td class="border-b-0.5 border-border-300/30 py-2 pr-4 align-top">UDP 514</td></tr></tbody></table>

</div>---

#### 1. Installation rsyslog<svg aria-hidden="true" class="transition-all opacity-100 scale-100" fill="currentColor" height="20" viewbox="0 0 20 20" width="20" xmlns="http://www.w3.org/2000/svg"></svg>

```bash
sudo apt update && sudo apt install rsyslog -y
sudo systemctl enable rsyslog
sudo systemctl start rsyslog
```

#### 2. Activation réception UDP 514

Dans `/etc/rsyslog.conf`, décommenter :<svg aria-hidden="true" class="transition-all opacity-100 scale-100" fill="currentColor" height="20" viewbox="0 0 20 20" width="20" xmlns="http://www.w3.org/2000/svg"></svg>

```
module(load="imudp")
input(type="imudp" port="514")
```

#### 3. Configuration du tri par équipement

`/etc/rsyslog.d/cisco.conf` :<svg aria-hidden="true" class="transition-all opacity-100 scale-100" fill="currentColor" height="20" viewbox="0 0 20 20" width="20" xmlns="http://www.w3.org/2000/svg"></svg>

```
:fromhost-ip, isequal, "192.168.99.14" /var/log/cisco/switch_bat_a.log
& /var/log/cisco/all.log
& stop

:fromhost-ip, isequal, "192.168.99.13" /var/log/cisco/switch_bat_b.log
& /var/log/cisco/all.log
& stop

:fromhost-ip, isequal, "192.168.99.1" /var/log/cisco/routeur.log
& /var/log/cisco/all.log
& stop
```

#### 4. Création du dossier et droits

<div aria-label="Code bash" class="relative group/copy bg-bg-000/50 border-0.5 border-border-400 rounded-lg focus:outline-none focus-visible:ring-2 focus-visible:ring-accent-100" id="bkmrk--1" role="group" tabindex="0"><div class="sticky opacity-0 group-hover/copy:opacity-100 group-focus-within/copy:opacity-100 top-2 py-2 h-12 w-0 float-right"><div class="absolute right-0 h-8 px-2 items-center inline-flex z-10"><div class="relative"><div class="transition-all opacity-100 scale-100"><svg aria-hidden="true" class="transition-all opacity-100 scale-100" fill="currentColor" height="20" viewbox="0 0 20 20" width="20" xmlns="http://www.w3.org/2000/svg"></svg>  
</div><div class="absolute inset-0 flex items-center justify-center"></div></div></div></div><div class="text-text-500 font-small p-3.5 pb-0"><svg aria-hidden="true" class="transition-all opacity-0 scale-50" fill="currentColor" height="20" viewbox="0 0 20 20" width="20" xmlns="http://www.w3.org/2000/svg"></svg></div><div class="overflow-x-auto"></div></div>```bash
sudo mkdir -p /var/log/cisco
sudo chown syslog:adm /var/log/cisco
sudo chmod 755 /var/log/cisco
sudo chmod 644 /var/log/cisco/*.log
sudo systemctl restart rsyslog
```

#### 5. Rotation des logs (365 jours)

`/etc/logrotate.d/cisco` :<svg aria-hidden="true" class="transition-all opacity-100 scale-100" fill="currentColor" height="20" viewbox="0 0 20 20" width="20" xmlns="http://www.w3.org/2000/svg"></svg>

```
/var/log/cisco/*.log {
    daily
    rotate 365
    compress
    missingok
    notifempty
    postrotate
        systemctl restart rsyslog
    endscript
}
```

#### 6. Installation Loganalyzer

<div aria-label="Code bash" class="relative group/copy bg-bg-000/50 border-0.5 border-border-400 rounded-lg focus:outline-none focus-visible:ring-2 focus-visible:ring-accent-100" id="bkmrk--2" role="group" tabindex="0"><div class="sticky opacity-0 group-hover/copy:opacity-100 group-focus-within/copy:opacity-100 top-2 py-2 h-12 w-0 float-right"><div class="absolute right-0 h-8 px-2 items-center inline-flex z-10"><div class="relative"><div class="transition-all opacity-100 scale-100"><svg aria-hidden="true" class="transition-all opacity-100 scale-100" fill="currentColor" height="20" viewbox="0 0 20 20" width="20" xmlns="http://www.w3.org/2000/svg"></svg>  
</div><div class="absolute inset-0 flex items-center justify-center"></div></div></div></div><div class="overflow-x-auto"></div></div>```bash
sudo apt install apache2 php libapache2-mod-php -y
cd /tmp
wget https://download.adiscon.com/loganalyzer/loganalyzer-4.1.13.tar.gz
tar xzvf loganalyzer-4.1.13.tar.gz
sudo cp -r loganalyzer-4.1.13/src /var/www/html/loganalyzer
sudo chmod 777 /var/www/html/loganalyzer
cd /var/www/html/loganalyzer
sudo touch config.php
sudo chmod 666 config.php
```

#### 7. Droits de lecture Loganalyzer

<div aria-label="Code bash" class="relative group/copy bg-bg-000/50 border-0.5 border-border-400 rounded-lg focus:outline-none focus-visible:ring-2 focus-visible:ring-accent-100" id="bkmrk--3" role="group" tabindex="0"><div class="sticky opacity-0 group-hover/copy:opacity-100 group-focus-within/copy:opacity-100 top-2 py-2 h-12 w-0 float-right"><div class="absolute right-0 h-8 px-2 items-center inline-flex z-10"><div class="relative"><div class="transition-all opacity-100 scale-100"><svg aria-hidden="true" class="transition-all opacity-100 scale-100" fill="currentColor" height="20" viewbox="0 0 20 20" width="20" xmlns="http://www.w3.org/2000/svg"></svg>  
</div><div class="absolute inset-0 flex items-center justify-center"></div></div></div></div><div class="overflow-x-auto"></div></div>```bash
sudo chmod 644 /var/log/syslog
sudo chmod 644 /var/log/cisco/*.log
```

#### 8. Vérifications<svg aria-hidden="true" class="transition-all opacity-100 scale-100" fill="currentColor" height="20" viewbox="0 0 20 20" width="20" xmlns="http://www.w3.org/2000/svg"></svg>

```bash
# Port 514 ouvert
sudo ss -ulnp | grep 514

# Paquets reçus
sudo tcpdump -i any port 514 -nn

# Fichiers de logs
ls /var/log/cisco/

# Logs en temps réel
tail -f /var/log/cisco/switch_bat_a.log
tail -f /var/log/cisco/switch_bat_b.log
tail -f /var/log/cisco/routeur.log

# Validation config rsyslog
sudo rsyslogd -N1 2>&1
```

#### Résultat final

- Logs reçus en temps réel depuis les 3 équipements
- Fichiers séparés par équipement
- Rotation 365 jours
- Interface web Loganalyzer accessible sur `http://192.168.99.7/loganalyzer`
- Filtrage par Facility, Severity, Hostname disponible