#!/bin/ash export PATH=$PATH:/opt/openslx/sbin:/opt/openslx/bin . /opt/openslx/config disable_remote_logging() { echo "Server doesn't seem to support hardware/usage stats - disabling logging" rm -f -- "/etc/cron.d/usage_stats" } # sends the hardware information of this machine generated by # systemd-hardware_stats_gather in /run/hwreport and /run/hwinfo report_hardware_info() { if [ -z "$SLX_REMOTE_LOG" ]; then disable_remote_logging return 1 fi local hwreport="/run/hwreport" if [ ! -s "$hwreport" ]; then echo "Missing hwreport file: $hwreport" # TODO send data without? return 1 fi # Read generated data and current uptime and send it local hwinfo="/run/hwinfo" if [ ! -s "$hwinfo" ]; then echo "Missing hwinfo file: $hwinfo" return 1 fi . "$hwinfo" # got everything, get the last infos local uptime=$(grep -oE '^[0-9]+' /proc/uptime) uuid=$(cat /etc/system-uuid) if [ -z "$uuid" ] || [ "${#uuid}" -ne "36" ]; then echo "No/malformed UUID, aborting" >&2 exit 1 fi # Combine manufacturer and model name (for displaying purposes) local model="$HW_MODEL" if [ "$HW_MANUF" != "Unknown" ]; then model="$model ($HW_MANUF)" fi # Get IP/subnet size local subnet="$( ip -o -f inet addr show br0 | awk '/scope global/ {print $4}' )" # just assume the uuid/mac dumped are valid here (its checked often enough :)) echo -n "Submitting to '$SLX_REMOTE_LOG' ... " curl --retry 4 --retry-connrefused --max-time 5 --retry-max-time 15 \ --data-urlencode "type=~poweron" --data-urlencode "uuid=$uuid" --data-urlencode "macaddr=$HW_MAC" \ --data-urlencode "uptime=$uptime" --data-urlencode "realcores=$HW_CORES" --data-urlencode "mbram=$HW_MBRAM" \ --data-urlencode "kvmstate=$HW_KVM" --data-urlencode "cpumodel=$HW_CPUMODEL" --data-urlencode "id44mb=$HW_ID44" \ --data-urlencode "badsectors=$HW_BADSECTORS" --data-urlencode "systemmodel=$model" --data-urlencode "subnet=$subnet" \ --data-urlencode "data@$hwreport" "$SLX_REMOTE_LOG" | grep -q "RESULT=0" local ret=$? if [ "$ret" -ne 0 ]; then echo "failed." disable_remote_logging return 1 fi echo "succeeded." rm -f -- "$hwreport" START=$(( $RANDOM % 5 )) DELAY=$(( $RANDOM % 20 )) cat > "/etc/cron.d/usage_stats" <<-EOF # Update usage statistics on server SHELL=/bin/sh PATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin:/opt/openslx/sbin:/opt/openslx/bin ${START}-59/5 * * * * root sleep ${DELAY}; /opt/openslx/scripts/cron-system_usage_update EOF # TODO remove this hack one day: Sometimes, aufs doesn't update the mtime of dirs # when creating files, so cron would not rescan the cron directory. touch "/etc/cron.d" # Trigger right now so resource usage gets updated /opt/openslx/scripts/cron-system_usage_update return 0 } report_hardware_info