Categories
GNU/Linux

GNU/Linux Telegram/Bot Mail Alert Script (Procmail/Python)

Small script to send a telegram chat message to a user when new mail arives. Script uses procmail and a small python script to process the message and to send the alert alert message through a telegram bot api.

.procmailrc:#LOGFILE=/path/to/pmlog
.procmailrc:#VERBOSE=yes
.procmailrc:#LOGABSTRACT=all
.procmailrc:INCLUDERC=/etc/procmail-rc/filter-potentialproblem-rc
.procmailrc:INCLUDERC=/etc/procmail-rc/filter-potentialproblem2-rc
.procmailrc:INCLUDERC=/etc/procmail-rc/filter-spamassassin08-rc
.procmailrc:
.procmailrc::0Wc:
.procmailrc:| env python ./.pmscript.py
.procmailrc:
.procmailrc::0
.procmailrc:.mail/

.pmscript.py:import sys
.pmscript.py:import email
.pmscript.py:import httplib
.pmscript.py:import urllib
.pmscript.py:
.pmscript.py:# Contstants...
.pmscript.py:email_addresses = ['test@example.com', 'info@example.com']
.pmscript.py:key = "telegram_botkey"
.pmscript.py:userid = "telegram_userid"
.pmscript.py:headers = {"Content-type": "application/x-www-form-urlencoded", "Accept": "text/plain"}
.pmscript.py:hostname = "api.telegram.org"
.pmscript.py:uri = "/bot" + key + "/sendMessage"
.pmscript.py:
.pmscript.py:# Read from stdin...
.pmscript.py:full_msg = sys.stdin.read()
.pmscript.py:msg = email.message_from_string(full_msg)
.pmscript.py:
.pmscript.py:# Get info from message...
.pmscript.py:mto = msg['to']
.pmscript.py:msubject = msg['subject']
.pmscript.py:mfrom = msg['from']
.pmscript.py:
.pmscript.py:# Check if e-mail in list...
.pmscript.py:for mailaddr in email_addresses:
.pmscript.py:  if mailaddr in mto:
.pmscript.py:    mrow = "[S6:NewMailAlert] \nFrom: " + mfrom + " \nSubject: " + msubject
.pmscript.py:    params = urllib.urlencode({'chat_id': userid, 'disable_web_page_preview': '1', 'text': mrow})
.pmscript.py:    connectie = httplib.HTTPSConnection(host=hostname, port=443)
.pmscript.py:    connectie.request("POST", uri, params, headers)
.pmscript.py:    resultaat = connectie.getresponse()
.pmscript.py:    if resultaat.status <> 200:
.pmscript.py:      print resultaat.status, resultaat.reason

Categories
GNU/Linux

GNU/Linux Auto-mount NFS Share

Bash script to auto-mount NFS share when it is available (and not already mounted).

#!/bin/bash
ping -c 1 -n 192.168.1.250 > /dev/null
if [ $? -eq 0 ] && [ ! -d /mnt/nas1/directory ]; then
 sudo mount -t nfs 192.168.1.250:/mnt/nfsmountpoint /mnt/nas1
fi
Categories
GNU/Linux

GNU/Linux Curl SOAP Request using Mutual SSL

POST a Soap Message using curl using Mutual SSL…

curl -k --cert certchain.pem:password --key server.key \
-d "<soapenv:Envelope xmlns:soapenv=\"http://schemas.xmlsoap.org/soap/envelope/\" xmlns:tot=\"http://totietoot.nl/services/testservice\" ><soapenv:Header/><soapenv:Body><tot:getTest><Name>%</Name></tot:getTest></soapenv:Body></soapenv:Envelope>" \
-H 'Content-Type: application/soap+xml' \
-H 'SOAPAction: "http://totietoot.nl/services/testservice/getTest"' \
https://totietoot.nl/testservice/getTest --tlsv1.2 -o result.xml -v
Categories
GNU/Linux

GNU/Linux Docker QuickRef

Simple Dockerfile example for a dockered teiid instance…

# HU Teiid Docker QuickRef:
# ->docker build -t dteiid-example .
# ->docker run --name dteiid-example -p 8081:8080 -p 9991:9990 -v /var/log/docker/dteiid-example/:/opt/jboss/teiid-10.0.0.Final/standalone/log/ --env-file=teiid-test.env --restart unless-stopped -it dteiid-example

FROM teiid/teiid:10.0.0.Final
MAINTAINER Tim van Kooten Niekerk (tim@totietoot.nl)

# Pass logs to host; Location on host needs chmod 1000:1000 so jboss can write...
RUN mkdir /opt/jboss/teiid-10.0.0.Final/standalone/log/
RUN chown -R jboss:jboss /opt/jboss/teiid-10.0.0.Final/standalone/log/
VOLUME /opt/jboss/teiid-10.0.0.Final/standalone/log/
# Add config files...
ADD customization /opt/jboss/teiid-10.0.0.Final/customization/

# Add Drivers...
ADD ojdbc7-12.1.0.1.0.jar /opt/jboss/teiid-10.0.0.Final/standalone/deployments/
ADD sqljdbc42.jar /opt/jboss/teiid-9.3.4/standalone/deployments/

# Deploy VDB's....
ADD cursuscatalogus-vdb-vdb.xml /opt/jboss/teiid-10.0.0.Final/standalone/deployments/

# Configure Environment and Start server...
CMD ["/opt/jboss/teiid-10.0.0.Final/customization/execute.sh"]

# You can expose ports...
EXPOSE 8081 8080
EXPOSE 9991 9990

Build a docker…

docker build -t dteiid-example .

Run, Start, Stop commands…

docker run --name dteiid-example -p 8081:8080 -p 9991:9990 --env-file=teiid-test.env --restart unless-stopped -it dteiid-example
docker ps -a
docker rm <containername|id>
docker start|stop <containername|id>
docker attach <containername|id>
docker image[s] [save|load|ls|rm|prune|...] [-[o|i] image.tar.gz]

Connect to a container…

docker exec [-u 0] -it <containername|id> bash
Categories
GNU/Linux

GNU/Linux TCPDump QuickRef

Some tcpdump examples.

tcpdump -vv -i eth0 -w tcpdump.log ‘tcp port 443’
tcpdump -vv -i eth0 -w tcpdump.log dst 145.89.57.121