hiera
Use “%” in hiera
–
“%”: “%”
%{hiera(‘%’)}
Use “%” in hiera
–
“%”: “%”
%{hiera(‘%’)}
./eicar.com: Win.Test.EICAR_HSB-1 FOUND
1 | echo "Win.Test.EICAR_HSB-1" >> /var/lib/clamav/whitelist.ign2 |
Un script de scan :
1 | #!/usr/bin/env bash # Scan and report for clamav # by Jerem # 20170313 TODAY=$(date +%Y.%m.%d) LOGFILE=/var/log/clamav/clamav_scan.$TODAY.log HOSTNAME=$(hostname) # --exclude=REGEX, --exclude-dir=REGEX if [ -f $LOGFILE ] then rm -f $LOGFILE fi date > $LOGFILE /usr/bin/clamscan -rio /data -l $LOGFILE date >> $LOGFILE if ((`/bin/grep Infected $LOGFILE | cut -d : -f2` > 0 )) then cat $LOGFILE | mail -s "Antivirus scan on $HOSTNAME" -a "From:supervision@plop.com" jerem@mail.fr fi |
Bench CPU via dd :
Pour 4 proc
1 | fulload() { dd if=/dev/zero of=/dev/null | dd if=/dev/zero of=/dev/null | dd if=/dev/zero of=/dev/null | dd if=/dev/zero of=/dev/null & }; fulload; read; killall dd |
DOC : http://docs.alerta.io/en/latest/
1 | apt-get install postfix apt-get install mongodb apt-get install python-pip pip install --upgrade pip pip install alerta-server |
1 | export ALERTA_SVR_CONF_FILE=/etc/alertad.conf mkdir /var/log/alerta/ |
1 | cat /etc/alertad.conf # Conf Alerta # http://docs.alerta.io/en/latest/configuration.html # BASIC DEBUG = False BASE_URL = '' LOGGER_NAME = 'alerta' LOG_FILE = '/var/log/alerta/alertad.log' # MONGODB MONGO_URI = 'mongodb://localhost:27017/monitoring' MONGO_DATABASE = 'monitoring' # CORS CORS_ORIGINS = [ 'http://127.0.0.1', 'http://localhost', 'http://192.168.50.45:8000', 'http://192.168.50.45', 'http://192.168.50.40' ] # AUTH AUTH_REQUIRED = False SECRET_KEY = '' ADMIN_USERS = ['astreinte@mail.fr'] CUSTOMER_VIEWS = False #OAUTH2_CLIENT_ID = None # Google or GitHub OAuth2 client ID and secret #OAUTH2_CLIENT_SECRET = None #ALLOWED_EMAIL_DOMAINS = ['*'] #ALLOWED_GITHUB_ORGS = ['*'] # #GITLAB_URL = None #ALLOWED_GITLAB_GROUPS = ['*'] TOKEN_EXPIRE_DAYS = 7 # API QUERY_LIMIT = 10000 HISTORY_LIMIT = 100 API_KEY_EXPIRE_DAYS = 365 AUTO_REFRESH_ALLOW = 'ON' SENDER_API_ALLOW = 'ON' # EMAIL EMAIL_VERIFICATION = False SMTP_HOST = 'localhost' SMTP_PORT = 25 MAIL_FROM = 'alerta@plop.com' SMTP_PASSWORD = '' # SUP BLACKOUT_DURATION = 86400 SEVERITY_MAP = { 'security': 0, 'critical': 1, 'major': 2, 'minor': 3, 'warning': 4, 'indeterminate': 5, 'cleared': 5, 'normal': 5, 'ok': 5, 'informational': 6, 'debug': 7, 'trace': 8, 'unknown': 9 } DEFAULT_SEVERITY = 'indeterminate' # Plug-ins PLUGINS = ['reject','amqp','alerta-mailer'] # amqp https://github.com/alerta/alerta-contrib/tree/master/plugins/amqp AMQP_URL = 'mongodb://localhost:27017/kombu' AMQP_TOPIC = 'notify' ORIGIN_BLACKLIST = ['foo/bar$', '.*/qux'] # reject all foo alerts from bar, and everything from qux ALLOWED_ENVIRONMENTS = ['blabla'] # reject alerts without allowed environments |
1 | cat alertad.sh #!/bin/bash ### BEGIN INIT INFO # Provides: alertad # Required-Start: $remote_fs $all # Should-Start: # Required-Stop: # Default-Start: 2 3 5 # Default-Stop: 0 6 # Description: Starts and stops alertad ### END INIT INFO ABIN=/usr/local/bin/alertad case $1 in # Startup alertad start) $ABIN & echo "starting..." ;; # Stop alertad stop) killall alertad echo "stopping..." ;; *) echo "stop ou start c'est tout" ;; esac |
DOC : http://docs.alerta.io/en/latest/webui.html
1 | cd /opt git clone https://github.com/alerta/angular-alerta-webui cd /opt/angular-alerta-webui/app/ |
1 | cat config.js 'use strict'; angular.module('config', []) .constant('config', { 'endpoint' : "http://"+window.location.hostname+":8080", 'provider' : "basic", // google, github, gitlab or basic // 'client_id' : "", // 'gitlab_url' : "https://gitlab.com", // replace with your gitlab server 'colors' : {}, // use default colors // 'colors' : { // 'severity': { // 'critical' : '#D8122A', // 'major' : '#EA680F', // 'minor' : '#FFBE1E', // 'warning' : '#BA2222', // 'indeterminate': '#A6ACA8', // 'cleared' : '#00AA5A', // 'normal' : '#00AA5A', // 'ok' : '#00AA5A', // 'informational': '#00A1BC', // 'debug' : '#9D006D', // 'security' : '#333333', // 'unknown' : '#A6ACA8' // }, // 'text': 'white', // 'highlight': 'lightgray' // }, 'severity' : {}, // use default severity codes // 'severity' : { // 'fatal': 0 // }, 'audio' : {}, // no audio // 'audio' : { // 'new' : '/audio/Bike Horn.mp3' // } // 'tracking_id' : "" // Google Analytics tracking ID eg. UA-NNNNNN-N }); |
1 | cat /etc/init.d/alerta-webui.sh #!/bin/bash ### BEGIN INIT INFO # Provides: alerta-webui # Required-Start: $remote_fs $all # Should-Start: # Required-Stop: # Default-Start: 2 3 5 # Default-Stop: 0 6 # Description: Starts and stops alerta-webui ### END INIT INFO AWDIR=/opt/angular-alerta-webui/app/ case $1 in # Startup alerta-webui start) cd $AWDIR && python -m SimpleHTTPServer 8000 & echo "starting..." ;; # Stop alerta-webui stop) for i in ` ps auxw | grep SimpleHTTPServer | grep -v grep | /usr/bin/awk '{print $2}'` ; do kill -9 $i ; done echo "stopping..." ;; *) echo "stop ou start c'est tout" ;; esac |
Doc : https://github.com/alerta/alerta-contrib/tree/master/integrations/mailer
1 | git clone https://github.com/alerta/alerta-contrib.git cd /opt/alerta-contrib/plugins/amqp python setup.py install |
1 | cd /opt/alerta-contrib/integrations/mailer vi mailer.py - 'config_file': '~/.alerta.conf', + 'config_file': '/etc/alerta-mailer.conf', |
1 | python setup.py install |
1 | cat /etc/alerta-mailer.conf [alerta-mailer] key = mail_to = astreinte@mail.fr mail_from = alerta@plop.com dashboard_url = http://192.168.50.45:8000 endpoint = http://192.168.50.45:8080 smtp_host = 127.0.0.1 smtp_port = 25 smtp_password = smtp_use_ssl = False debug = True skip_mta = False email_type = html mail_localhost = plop.com amqp_url = mongodb://127.0.0.1:27017/kombu amqp_topic = notify mail_template = /opt/alerta-contrib/integrations/mailer/email.tmpl mail_template_html = /opt/alerta-contrib/integrations/mailer/email.html.tmpl |
alerta-mailer
1 | cat /etc/cron.d/alerta-mailer_restart 0 */2 * * * root /etc/init.d/alerta-mailer-init.sh stop && /bin/sleep 2 && /etc/init.d/alerta-mailer-init.sh start >> /var/log/alerta/restart 2>&1 |
1 | cat /etc/init.d/alerta-mailer-init.sh #!/bin/bash ### BEGIN INIT INFO # Provides: alerta-mailer # Required-Start: $remote_fs $all # Should-Start: # Required-Stop: # Default-Start: 2 3 5 # Default-Stop: 0 6 # Description: Starts and stops alerta-mailer. ### END INIT INFO AMBIN=/usr/local/bin/alerta-mailer case $1 in # Startup alerta-mailer start) $AMBIN & echo "starting..." ;; # Stop alerta-mailer stop) killall alerta-mailer echo "stopping..." ;; *) echo "stop ou start c'est tout" ;; esac |
compose(single)/swarm(multi host)
http://mesos.apache.org/
1 | ~# docker search ubuntu ~# docker pull ubuntu:latest ~# docker push jeba/ubuntu |
1 | ~# docker tag jeba/ubuntu jeba/plop |
1 | ~# docker inspect jeba/ubuntu | jq |
daemon
1 | ~# docker run -d |
interactiv (stdin) -t terminal
1 | ~# docker run -it --name myubuntu ubuntu bash |
–rm : rm on stop
–restart always
exit whithout kill
ctrl+p+q
re attach
1 | ~# docker container attach [ID] |
1 | ~# docker container exec -i -t [id] <command> |
1 | ~# docker container logs ~# docker container logs -f ~# docker container logs --tail 20 |
1 | ~# docker container stop (sigterm) ~# docker container kill (sigkill) |
1 | ~# docker container run -d -p 80:80 nginx ~# docker container exec -it nginx bash |
1 | ~# docker container commit nginx mon_nginx:0.1 |
1 | ~# docker container prune ~# docker image prune |
https://docs.docker.com/engine/reference/builder/
FROM : image de base
RUN : modif du fs
COPY : cp from host to container
ADD : cp also from an URL
ENTRYPOINT : run at start of the container
CMD : run at start of the container (can be overridden)( parameters for ENTRYPOINT (if exist))
ENV : set env variables
ARG : set variables
USER : set user
WORKDIR : set pwd
VOLUME
EXPOSE
SHELL
LABEL
HEALTHCHECK
STOPSIGNAL
1 | ~# docker image build -t name:tag <context_path> ( -f <file> if not "Dockerfile" ) |
1 | ~# cat Dockerfile FROM ubuntu:latest RUN apt-get update && \ apt-get install iputils-ping -y VOLUME /var/www ENTRYPOINT ["ping"] CMD ["8.8.8.8"] |
1 | ~# docker container run -v /home/wam:/container/home/ ~# docker container run -v /home/wam:/container/home/:ro ~# docker volume create voltest (--driver local --opt type=btrfs --opt device=/dev/sda2) (OR --driver local --opt type=tmpfs --opt device=tmpfs --opt o=size=100m,uid=1000) ~# ~# ls /var/lib/docker/volumes/voltest/ ~# docker container run -v voltest:/container/home/ |
map to host (host:container)1
~# docker container run -d -p 80:80 nginx
auto map (on random port)1
~# docker container run -d -P nginx
EXPOSE in dockerfile is informative !
1 | ~# docker network create --driver bridge mynetwork ~# docker network create --driver bridge --subnet 10.0.0.1/24 mynetwork |
no dns resolv on docker0 (auto create bridge)
dns resolv auto activate on manually created bridge
ex:1
~# docker network create -d bridge --subnet 192.168.69.0/24 testnet
~# docker run -d -P --network=testnet jeba/nginx:0.1
export DOCKER_TLS_VERIFY=”1”
export DOCKER_HOST=”tcp://127.0.0.1:2375”
export DOCKER_CERT_PATH=”/home/jerem/.docker/certs”
export DOCKER_MACHINE_NAME=”myDock”
Info1
~# docker system
Clean1
~# docker system prune
Exit/detach1
~# ctrl+p+q
rm all1
~# docker rm -f $(docker ps -aq)
Expose dockerengine port and use insecure registry1
~# cat /lib/systemd/system/docker.service
ExecStart=/usr/bin/dockerd -H fd:// -H tcp://0.0.0.0:2375
ExecStart=/usr/bin/dockerd -H fd:// -H tcp://0.0.0.0:2375 -insecure-registry myregistry:5000
ExecStart=/usr/bin/dockerd -H fd:// -H tcp://0.0.0.0:2375 --tlsverify --tlscacert=/etc/docker/certs.d/ca.pem --tlscert=/etc/docker/certs.d/server-cert.pem --tlskey=/etc/docker/certs.d/server-key.pem
Create stack = overlay network and services (on swarm with compose)1
~# docker stack deploy -c compose.yml mystack
load balancer
https://docs.traefik.io/
Webgui for swarm (or not)
https://github.com/kubernetes/helm
http://helm.sh/
https://github.com/kubernetes/minikube
https://www.nomadproject.io/
https://www.terraform.io/docs/providers/docker/index.html
curl ‘https://registry.hub.docker.com/v2/repositories/heketi/heketi/tags/'|jq ‘.”results”[][“name”]’
Copy table1
sfdisk -d /dev/sdb | sfdisk -f /dev/sda
Create raid1
mdadm --create --verbose /dev/md2 --level=1 --raid-devices=2 /dev/sdc /dev/sdd
Add disk to raid1
mdadm --manage /dev/md0 --add /dev/sda1
Speed up rebuild1
echo 50000 > /proc/sys/dev/raid/speed_limit_min
1 | ~# ~? Supported escape sequences: ~. - terminate connection (and any multiplexed sessions) ~B - send a BREAK to the remote system ~C - open a command line ~R - request rekey ~V/v - decrease/increase verbosity (LogLevel) ~^Z - suspend ssh ~# - list forwarded connections ~& - background ssh (when waiting for connections to terminate) ~? - this message ~~ - send the escape character by typing it twice (Note that escapes are only recognized immediately after newline.) |
1 | ~# grep AllowUsers /etc/ssh/sshd_config AllowUsers root@93.14.29.25 jerem none |
1 | ssh -o ServerAliveInterval=5 -o ServerAliveCountMax=1 10.0.0.1 |
-L : local
-f : background
-n : redirect stdin > /dev/null
1 | ~# ssh -L 8080:localhost:80 jerem.unvrai.info -f -n ~# curl http://localhost:8080 <h1> unvrai.info welcome page </h1> |
1 | ~# ssh -L 8080:web.unvrai.info:80 jerem.unvrai.info -f -n ~# curl http://localhost:8080 <h1> web.unvrai.info home page </h1> |
1 | ~# ssh -R 8080:localhost:80 jerem@unvrai.info -f -n ~# curl http://unvrai.info:8080 <h1> my local welcome page </h1> |
SSH connection through host in the middle
1 | ~# ssh -t reachable_host ssh unreachable_host |
Testing remote connection to port
1 | timeout 1 bash -c "</dev/<proto>/<host>/<port>" >/dev/null 2>&1 ; echo $? |
1 | ~$ mkdir /opt/doc/ansible ~$ sshfs jerem@server.fr:doc/ansible /opt/doc/ansible |
1 | ~# grep sshfs /etc/fstab user@machine:/répertoire/distant /mnt/mon_rep fuse.sshfs port=22,user,noatime,_netdev 0 0 |
1 | ~# grep X11 /etc/ssh/sshd_config X11Forwarding yes #X11DisplayOffset 10 X11UseLocalhost no |
1 | ~# ssh-keygen -f "/home/jerem/.ssh/known_hosts" -R 10.0.0.10 |
1 | /var/log/apache2/*.log { daily missingok rotate 366 compress compresscmd /bin/bzip2 compressext .bz2 notifempty create 640 root adm sharedscripts postrotate /etc/init.d/apache2 reload > /dev/null endscript } |
Curator est un outil qui va permettre de purger d’anciens indices ou snapshot ES
Need :
1 | ~# pip install elasticsearch-curator==2.1.2 |
1 | $> curator delete --prefix .marvel- --older-than 15 |
1 | 15 3 * * * elasticsearch /usr/local/bin/curator --host 127.0.0.1 delete --prefix logstash- --older-than 360 --time-unit days --timestring '%Y.%m.%d' |
1 | ~# curl -XGET 'http://localhost:9200/_cluster/health?pretty' |
1 | ~# curl -XGET 'localhost:9200/_nodes?pretty' |
1 | ~# curl -XGET 'localhost:9200/_stats?pretty' |