Skip to content

Instantly share code, notes, and snippets.

@ao-kenji
Last active October 17, 2020 11:23
Show Gist options
  • Select an option

  • Save ao-kenji/2a279ec4ae483e14b0a2b945fab3e219 to your computer and use it in GitHub Desktop.

Select an option

Save ao-kenji/2a279ec4ae483e14b0a2b945fab3e219 to your computer and use it in GitHub Desktop.
[WIP] PandoraFMS agent for OpenBSD patch
diff -urN pandorafms_agent.orig/unix/OpenBSD/README pandorafms_agent/unix/OpenBSD/README
--- pandorafms_agent.orig/unix/OpenBSD/README Thu Jan 1 09:00:00 1970
+++ pandorafms_agent/unix/OpenBSD/README Sun Sep 20 09:48:09 2020
@@ -0,0 +1,23 @@
+README for OpenBSD
+
+<Brief instruction> (under construction)
+
+1. Add perl YAML-Tiny module by pkg_add
+
+% doas pkg_add p5-YAML-Tiny
+
+2. Create a configuration directory
+
+% doas mkdir /etc/pandora
+
+3. Install scripts
+
+% doas pandora_agent_install --install /
+
+4. Enable rc.d script
+
+% doas rcctl enable pandora_agent
+
+5. Start pandora_agent by manually
+
+% doas rcctl start pandora_agent
diff -urN pandorafms_agent.orig/unix/OpenBSD/pandora_agent pandorafms_agent/unix/OpenBSD/pandora_agent
--- pandorafms_agent.orig/unix/OpenBSD/pandora_agent Thu Jan 1 09:00:00 1970
+++ pandorafms_agent/unix/OpenBSD/pandora_agent Sun Sep 20 09:41:48 2020
@@ -0,0 +1,18 @@
+#!/bin/ksh
+
+# **********************************************************************
+# Pandora FMS Agent Daemon launcher for OpenBSD
+# (c) 2020 Kenji Aoyama <[email protected]>
+#
+# **********************************************************************
+
+daemon="/usr/local/bin/pandora_agent"
+daemon_flags="/etc/pandora"
+
+. /etc/rc.d/rc.subr
+
+pexp="$(eval echo /usr/bin/perl ${daemon}${daemon_flags:+ ${daemon_flags}})"
+rc_bg=YES
+rc_reload=NO
+
+rc_cmd $1
diff -urN pandorafms_agent.orig/unix/OpenBSD/pandora_agent.conf pandorafms_agent/unix/OpenBSD/pandora_agent.conf
--- pandorafms_agent.orig/unix/OpenBSD/pandora_agent.conf Thu Jan 1 09:00:00 1970
+++ pandorafms_agent/unix/OpenBSD/pandora_agent.conf Sat Oct 17 19:40:32 2020
@@ -0,0 +1,231 @@
+# Base config file for Pandora FMS agents
+# Version 7.0NG.747, OpenBSD Version
+# Licensed under GPL license v2,
+# Copyright (c) 2003-2010 Artica Soluciones Tecnologicas
+# http://www.pandorafms.com
+
+# General Parameters
+# ==================
+
+server_ip localhost
+server_path /var/spool/pandora/data_in
+temporal /tmp
+logfile /var/log/pandora/pandora_agent.log
+#include /etc/pandora/pandora_agent_alt.conf
+#broker_agent name_agent
+
+# Interval in seconds, 300 by default
+interval 300
+
+# Debug mode renames XML in the temp folder and continues running
+debug 0
+
+# By default, agent takes machine name
+#agent_name adama
+
+#Parent agent_name
+#parent_agent_name parent_name
+
+# Agent description
+#description Demo agent
+
+# Group assigned for this agent (descriptive, p.e: Servers)
+group Servers
+
+# Group password (if defined).
+#group_password
+
+# Autotime: Enforce to server to ignore timestamp coming from this
+# agent, used when agents has no timer or it's inestable. 1 to enable
+# this feature
+# autotime 1
+
+# Timezone offset: Difference with the server timezone
+#timezone_offset 0
+
+# Agent position paramters
+# Those parameters define the geographical position of the agent
+
+# latitude
+#latitude 0
+# longitude
+#longitude 0
+# altitude
+#altitude 0
+
+#Position description
+#position_description Madrid, centro
+
+# By default agent try to take default encoding defined in host.
+# encoding UTF-8
+
+# Listening TCP port for remote server. By default is 41121 (for tentacle)
+# if you want to use SSH use 22, and FTP uses 21.
+server_port 41121
+
+# Transfer mode: tentacle, ftp, ssh or local
+transfer_mode tentacle
+
+# Transfer mode user: Owner of files copied on local transfer mode (default apache)
+#transfer_mode_user apache
+
+# timeout in seconds for file transfer programs execution (30 by default)
+#transfer_timeout 30
+
+# Server password (Tentacle or FTP). Leave empty for no password (default).
+#server_pwd mypassword
+
+# Set to yes/no to enable/disable OpenSSL support for Tentacle (disabled by default).
+#server_ssl no
+
+# Extra options for the Tentacle client (for example: server_opts -v -r 5).
+#server_opts
+
+# delayed_startup defines number of seconds before start execution
+# for first time when startup Pandora FMS Agent
+#delayed_startup 10
+
+# Pandora nice defines priority of execution. Less priority means more intensive execution
+# A recommended value is 10. 0 priority means no Pandora CPU protection enabled (default)
+#pandora_nice 0
+
+# Cron mode replace Pandora FMS own task schedule each XX interval seconds by the use
+# of old style cron. You should add to crontab Pandora FMS agent script to use this mode.
+# This is disabled by default, and is not recommended. Use Pandora FMS internal scheduler
+# is much more safe.
+#cron_mode
+
+# If set to 1 allows the agent to be configured via the web console (Only Enterprise version)
+#remote_config 1
+
+# Default 0, set to 1 to avoid module executions and report to server
+# standby 1
+
+# If set to 1 start Drone Agent's Proxy Mode
+#proxy_mode 1
+
+# Max number of simmultaneus connection for proxy (by default 10)
+#proxy_max_connection 10
+
+# Proxy timeout (by default 1s)
+#proxy_timeout 1
+
+# Number of threads to execute modules in parallel
+#agent_threads 1
+
+# User the agent will run as
+#pandora_user root
+
+# Agent mode: Learn (default), No-learn, Autodisable
+# agent_mode autodisable
+
+# Secondary groups. You can select several groups separated by comma.
+# secondary_groups Group1,Group2
+
+# Secondary server configuration
+# ==============================
+
+# If secondary_mode is set to on_error, data files are copied to the secondary
+# server only if the primary server fails. If set to always, data files are
+# always copied to the secondary server.
+#secondary_mode on_error
+#secondary_server_ip localhost
+#secondary_server_path /var/spool/pandora/data_in
+#secondary_server_port 41121
+#secondary_transfer_mode tentacle
+#secondary_transfer_timeout 30
+#secondary_server_pwd mypassword
+#secondary_server_ssl no
+#secondary_server_opts
+
+# Module Definition
+# =================
+
+# System information
+
+# vmstat syntax depends on system configuration, please check before use it
+module_begin
+module_name cpu_user
+module_type generic_data
+module_interval 1
+module_exec vmstat 1 2 | tail -1 | awk '{ print $16 }'
+module_max 100
+module_min 0
+module_description User CPU Usage (%)
+module_end
+
+module_begin
+module_name cpu_system
+module_type generic_data
+module_interval 1
+module_exec vmstat 1 2 | tail -1 | awk '{ print $17 }'
+module_max 100
+module_min 0
+module_description System CPU Usage (%)
+module_end
+
+module_begin
+module_name cpu_idle
+module_type generic_data
+module_interval 1
+module_exec vmstat 1 2 | tail -1 | awk '{ print $18 }'
+module_max 100
+module_min 0
+module_description CPU Idle (%)
+module_end
+
+module_begin
+module_name Load Average
+module_type generic_data
+module_exec uptime | cut -d "," -f 4 | cut -d ":" -f 2 | sed "s/ //g"
+module_description Average process in CPU (Last minute)
+module_end
+
+module_begin
+module_name disk_root_free
+module_type generic_data
+module_exec df -kh / | tail -1 | awk '{ print 100-$5 }'
+module_max 100
+module_min 0
+module_description Free disk Percentage of root partition
+module_end
+
+module_begin
+module_name memfree
+module_type generic_data
+module_exec vmstat 1 2 | tail -1 | awk '{print $4}' | sed "s/M$//"
+module_description Unused RAM memory (MB)
+module_end
+
+module_begin
+module_name proctotal
+module_type generic_data
+module_exec ps -A | wc -l | sed "s/ //g"
+module_end
+
+# Process information
+
+module_begin
+module_name sshDaemon
+module_type generic_proc
+module_exec ps -A | grep sshd | grep -v "grep" | wc -l | sed "s/ //g"
+module_end
+
+# Async data example
+
+module_begin
+module_name LastLogin
+module_type async_string
+module_exec last | head -1
+module_end
+
+# Plugin example
+
+# This parses /var/log/auth.log file, under the module name "syslog"
+# And search for "sshd" string into it, sending only that information.
+
+module_plugin grep_log /var/log/auth.log Syslog sshd
+
+# Plugin for inventory on the agent (Only Enterprise)
+
+# module_plugin inventory 1 cpu ram video nic hd cdrom software
diff -urN pandorafms_agent.orig/unix/pandora_agent_installer pandorafms_agent/unix/pandora_agent_installer
--- pandorafms_agent.orig/unix/pandora_agent_installer Thu Jul 2 18:06:26 2020
+++ pandorafms_agent/unix/pandora_agent_installer Mon Sep 14 09:15:13 2020
@@ -17,7 +17,8 @@
LOG_TIMESTAMP=`date +"%Y/%m/%d %H:%M:%S"`
PREFIX=/usr
-if [ "$OS_NAME" = "FreeBSD" ] || [ "$OS_NAME" = "NetBSD" ]
+if [ "$OS_NAME" = "FreeBSD" ] || [ "$OS_NAME" = "NetBSD" ] \
+ || [ "$OS_NAME" = "OpenBSD" ]
then
PREFIX=/usr/local
fi
@@ -60,6 +61,12 @@
DAEMON_SCRIPT=$OS_NAME/pandora_agent
PANDORA_PERL_PATH=/usr/pkg/bin/perl
;;
+OpenBSD)
+ PANDORA_CFG=/etc/pandora
+ PANDORA_STARTUP=/etc/rc.d/pandora_agent
+ DAEMON_SCRIPT=$OS_NAME/pandora_agent
+ PANDORA_PERL_PATH=/usr/bin/perl
+ ;;
esac
MODE=$1
@@ -99,7 +106,7 @@
exit 2
fi
-if [ -z "`echo Linux HP-UX SunOS AIX Solaris Darwin BSD bsd FreeBSD NetBSD | grep \"$OS_NAME\"`" ]
+if [ -z "`echo Linux HP-UX SunOS AIX Solaris Darwin BSD bsd FreeBSD NetBSD OpenBSD | grep \"$OS_NAME\"`" ]
then
echo "This system: '$OS_NAME' is not supported by this script"
echo "Please make the install yourself as it's described in documentation"
@@ -305,7 +312,8 @@
# Backup the configuration file
cp -f "$AGENT_CFG" "${AGENT_CFG}.bak"
- if [ "$OS_NAME" = "FreeBSD" ] || [ "$OS_NAME" = "NetBSD" ]
+ if [ "$OS_NAME" = "FreeBSD" ] || [ "$OS_NAME" = "NetBSD" ] \
+ || [ "$OS_NAME" = "OpenBSD" ]
then
sed -e "\|^PATH=|s|=|=$PANDORA_BASE$PREFIX/bin:|" \
-e "s|/usr/local/etc/pandora|$PANDORA_BASE$PANDORA_CFG|g" \
@@ -427,7 +435,8 @@
chmod 711 $PANDORA_BASE$PANDORA_LOG_DIR
chmod 640 $PANDORA_BASE$PANDORA_LOG_DIR/$PANDORA_LOG
chown $PANDORA_USER:0 $PANDORA_BASE$PANDORA_LOG_DIR/$PANDORA_LOG 2>/dev/null
- if [ "$OS_NAME" = "FreeBSD" ] || [ "$OS_NAME" = "NetBSD" ]
+ if [ "$OS_NAME" = "FreeBSD" ] || [ "$OS_NAME" = "NetBSD" ] \
+ [ "$OS_NAME" = "OpenBSD" ]
then
chown $PANDORA_USER:daemon $PANDORA_BASE$PANDORA_TEMP 2>/dev/null
chmod -R 770 $PANDORA_BASE$PANDORA_TEMP
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment