Restart failed program every 5 min

Problem

  • Your program fails regularly
  • You need to check if it is running and if not, restart it

Solution

Create a script:

nano restart.sh

Put in the code and replace htop with your program name:

#!/bin/sh

ps cax | grep htop > /dev/null
if [ $? -eq 0 ]; then
echo “Process running.”
else
echo “Process is down.”
fi

Make the script executable:

chmod +x restart.sh

Create a cron job:

crontab -e

Create a new line (replace /home/user/):

*/5 * * * * /home/user/restart.sh

Fin.

 

System wide proxy settings for Xubuntu (16.10)

Problem

  • You have to set http etc. proxy settings for all application
  • XUbuntu GUI is not helpful ūüėČ

Solution

Step 1: Edit environment

sudo nano /etc/environment

Append these lines (fill in your proxy):

http_proxy=http://yourproxy:8080/
https_proxy=http://yourproxy:8080/
HTTP_PROXY=http://yourproxy:8080/
HTTPS_PROXY=http://yourproxy:8080/

To load the new variables:

source /etc/environment

Step 2: Edit apt

Go to /etc/apt/apt.conf.d/ and create a file named 95proxies.

sudo nano /etc/apt/apt.conf.d/95proxies

Fill in these lines:

Acquire::http::proxy “http://yourproxy:8080/”;
Acquire::ftp::proxy “ftp://yourproxy:8080/”;
Acquire::https::proxy “http://yourproxy:8080/”;

Fin.

Import GPX into Splunk

Problem

  • You want to import a GPX File into Splunk
  • You want to define a special sourcetype

Solution

This is the example

<?xml version=”1.0″ encoding=”UTF-8″?>
<gpx version=”1.1″ xsi:schemaLocation=”http://www.topografix.com/GPX/1/1 http://www.topografix.com/GPX/1/1/gpx.xsd&gt;
<trk>
<trkseg>
<trkpt lon=”13.7235536575317383″ lat=”51.0877876281738281″>
<ele>154.0</ele>
<time>2016-04-29T15:39:38.000Z</time>
</trkpt>
<trkpt lon=”13.7235345840454102″ lat=”51.0876770019531250″>
<ele>155.0</ele>
<time>2016-04-29T15:39:47.000Z</time>
</trkpt>
<trkpt lon=”13.7242536544799805″ lat=”51.0879554748535156″>
<ele>152.0</ele>
<time>2016-04-29T15:40:11.000Z</time>
</trkpt>
<trkpt lon=”13.7242536544799805″ lat=”51.0879554748535156″>
<ele>152.0</ele>
<time>2016-04-29T15:40:13.000Z</time>
</trkpt>
<trkpt lon=”13.7242908477783203″ lat=”51.0884094238281250″>
<ele>149.0</ele>
<time>2016-04-29T15:40:29.000Z</time>
</trkpt>
</trkseg>
</trk>
</gpx>

Go to the Splunk preferences and add a new sourcetype with the following properties:

BREAK_ONLY_BEFORE = <trkpt

KV_MODE = xml

NO_BINARY_CHECK = true

SHOULD_LINEMERGE = true

pulldown_type = true

FIELDALIAS-rootfields = trkpt.ele as Hight trkpt{@lat} as Latitude trkpt{@lon} as Longitude

This will create events based on TrackPoint. In addition, latitude, longitude and hight will be extracted as extra fields.

gpx

If you want to include RoutePoints (see GPX Wikipedia), you only have to change the BREAK_ONLY_BEFORE  from <trkpt to <\w\w\wpt 

timechart

Fin.

Where to find Windows system log files

Problem

  • You are looking for the system / security / application log file, which are displayed by the Windows Event Viewer.
  • You need to copy the log files to another computer.

Solution

The log files can be found under

C:\Windows\System32\winevt\Logs

Just copy the files ending with “evtx“. You can open them with the Windows Event Viewer on every other computer, even those, you have no access on the original computer (no permission to watch; in that case, boot with linux, copy files …).

Fin

 

Raspberry PI – Static WIFI IP address

Problem

  • ¬†Raspberry PI is configured using Wifi and DHCP by default (Jessie)

Solution

The solution is simple. Open the file /etc/dhcpcd.conf as root (sudo nano /etc/dhcpcd.conf)

At the end of the file, add the following lines:

interface wlan0
static ip_address=192.168.xxx.xxx/24
static routers=192.168.2.1
static domain_name_servers=192.168.2.1

  • static ip_address: your desired IP address
  • static routers: your gateway
  • static domain_name _servers: your DNS server

Save the file and reboot:

sudo reboot

Fin.

Einfache √úberstundenerfassung mit Excel

Problem

  • Sie ben√∂tigen eine einfach und √ľbersichtliche Art um Ihre √úberstunden zu verwalten.
  • Eine vollwertige Zeiterfassung ist zuviel f√ľr Ihre Bed√ľrfnisse.

Lösung

Ich habe eine kleine und √ľbersichtliche Excel-Mappe erstellt, bestehend aus 3 Tabellen:

  1. √úbersicht – √úbersicht √ľber erarbeitete/geenommene sowie Saldo-√úberstunden
  2. √úberstunden – hier werden die erarbeiteten √úberstunden angegeben.
  3. √úS-Abbau – hier werden die genommenen √úberstunden angegeben.

Das ganze ist ohne Makros erstellt und kann frei verwendet werden. Die Überstundenerfassung finden Sie hier.

Viel Spass.

 

 

Icinga2 – Change layout of email notifications

Problem

  • You want to change the layout of the email notifications in Icinga2
  • You want to know, which variables Icinga2 provides

Solution

In Icinga2, emails are sent by a command line script (default is one for host and one for service notifications). In a default installation these scripts can be found under/etc/icinga2/scripts

The scripts are easy structured. At first, a variable template is set with a string which defines the mail body. After this template is “printed” and sent to mail. The -s parameter defines the subject of the email notification. (How to setup mail¬†is described in an another¬†post).

The default template looks like this:

#!/bin/sh
template=`cat <<TEMPLATE
***** Icinga *****

Notification Type: $NOTIFICATIONTYPE

Host: $HOSTALIAS
Address: $HOSTADDRESS
State: $HOSTSTATE

Date/Time: $LONGDATETIME

Additional Info: $HOSTOUTPUT

Comment: [$NOTIFICATIONAUTHORNAME] $NOTIFICATIONCOMMENT
TEMPLATE
`

/usr/bin/printf “%b” “$template” | mail -s “$NOTIFICATIONTYPE – $HOSTDISPLAYNAME is $HOSTSTATE” $USEREMAIL

This means, you can change the mail body and the subject of the email.

Variables

Unfortunately, a listing of the available variables in Icinga2 are difficult to find. I found them in the migration chapter of the Icinga2 docs.

If you need more information in your notification, pick them out of the list. To use a new variable for the template or subject, you have to register them in the environment.

The environment is set in the commands.conf under /etc/icinga2/conf.d/

object NotificationCommand “mail-service-notification” {
import “plugin-notification-command”

command = [ SysconfDir + “/icinga2/scripts/mail-service-notification.sh” ]

env = {
NOTIFICATIONTYPE = “$notification.type$”
SERVICEDESC = “$service.name$”
HOSTALIAS = “$host.display_name$”
HOSTADDRESS = “$address$”
SERVICESTATE = “$service.state$”
LONGDATETIME = “$icinga.long_date_time$”
SERVICEOUTPUT = “$service.output$”
NOTIFICATIONAUTHORNAME = “$notification.author$”
NOTIFICATIONCOMMENT = “$notification.comment$”
HOSTDISPLAYNAME = “$host.display_name$”
SERVICEDISPLAYNAME = “$service.display_name$”
USEREMAIL = “$user.email$”
}
}

In the “env = {” statement, a mapping between the Icinga2 variables and the command variables is build up. If you want to add the needed variable, just add a new line.

Fin