Probe

GNU/Linux BASH website probe using CURL

Small script I used to probe a website. Script should returns a message only when the state changes.

#!/bin/bash

function funcProbe {
  curl ${1} -k -I -s | grep "HTTP/1.1 200 OK" > /dev/null
  if [ $? -ne 0 ]; then
    if [ ! -f /tmp/prb-${2}-DOWN ]; then
      echo "[S2:Probe-${2}] Service DOWN Detected!"
    fi
    touch /tmp/prb-${2}-DOWN
    rm -f /tmp/prb-${2}-UP
  else
    if [ ! -f /tmp/prb-${2}-UP ]; then
      echo "[S2:Probe-${2}] Service UP Detected!"
    fi
    touch /tmp/prb-${2}-UP
    rm -f /tmp/prb-${2}-DOWN
  fi
}

funcProbe https://tech.ne7.nl/ Repository

GNU/Linux Python3 Mail Probe

A small script I used to quickly send a mail messages (probe).

#!/usr/bin/env python3
# Small mail probe...
from datetime import datetime
import smtplib
from email.message import EmailMessage
from email.mime.text import MIMEText

# Configured values...
senderid = "my-name"
subject = "MailProbe from " + senderid
body = "*** This is a mail probe message to verify the connection ***"
sender = "sender@example.com"
recipients = ["receiver@example.com"]
password = "store-password-somewhere-else"

# Mail sender function...
def send_email(subject, body, sender, recipients, password):
    now = datetime.now()
    msg = MIMEText(body)
    msg['X-Ne7-Probe-Firetime'] = now.strftime("%Y-%m-%dT%H:%M:%S")
    msg['Subject'] = subject
    msg['From'] = sender
    msg['To'] = ', '.join(recipients)
    smtp_server = smtplib.SMTP_SSL('smtp.example.com', 465)
    smtp_server.login(sender, password)
    smtp_server.sendmail(sender, recipients, msg.as_string())
    smtp_server.quit()

send_email(subject, body, sender, recipients, password)