From 1f8db156eb9f05ed88d74057774815b94a5b437c Mon Sep 17 00:00:00 2001 From: f0o Date: Tue, 19 May 2015 14:25:17 +0000 Subject: [PATCH] Introduce own librenms user and remove rrds when removing a device --- doc/Installation/Installation-(Debian-Ubuntu).md | 12 ++++++++++-- doc/Installation/Installation-(RHEL-CentOS).md | 16 +++++++++++++--- .../Installation-Lighttpd-(Debian-Ubuntu).md | 13 +++++++++++-- includes/definitions.inc.php | 2 ++ includes/functions.php | 9 ++++++++- librenms.cron | 2 ++ librenms.nonroot.cron | 7 +++++++ 7 files changed, 53 insertions(+), 8 deletions(-) create mode 100644 librenms.nonroot.cron diff --git a/doc/Installation/Installation-(Debian-Ubuntu).md b/doc/Installation/Installation-(Debian-Ubuntu).md index eecd4c295..201c7e08c 100644 --- a/doc/Installation/Installation-(Debian-Ubuntu).md +++ b/doc/Installation/Installation-(Debian-Ubuntu).md @@ -55,6 +55,11 @@ Adding the above line to `/etc/snmp/snmpd.conf` and running `service snmpd resta In `/etc/php5/apache2/php.ini` and `/etc/php5/cli/php.ini`, ensure date.timezone is set to your preferred time zone. See http://php.net/manual/en/timezones.php for a list of supported timezones. Valid examples are: "America/New York", "Australia/Brisbane", "Etc/UTC". +### Adding the librenms-user ### + + useradd librenms -d /opt/librenms -M -r + usermod -a -G librenms www-data + ### Cloning ### LibreNMS is installed using git. If you're not familiar with git, check out the [git book][2] or the tips at [git ready][3]. The initial install from github.com is called a `git clone`; subsequent updates are done through `git pull`. @@ -81,9 +86,12 @@ To prepare the web interface (and adding devices shortly), you'll need to create First, create and chown the `rrd` directory and create the `logs` directory: mkdir rrd logs - chown www-data:www-data logs/ rrd/ + chown www-data:www-data logs + chmod 775 rrd + chown librenms:librenms rrd > NOTE: If you're not running Ubuntu or Debian, you will need to change `www-data` to the user and group which run the Apache web server. +> If you're planing on running rrdcached, make sure that the path is also chmod'ed to 775 and chown'ed to librenms:librenms. Next, add the following to `/etc/apache2/sites-available/librenms.conf`: @@ -168,7 +176,7 @@ LibreNMS uses Job Snijders' [poller-wrapper.py][1]. By default, the cron job ru Create the cronjob - cp librenms.cron /etc/cron.d/librenms + cp librenms.nonroot.cron /etc/cron.d/librenms ### Daily Updates ### diff --git a/doc/Installation/Installation-(RHEL-CentOS).md b/doc/Installation/Installation-(RHEL-CentOS).md index a2e093fcf..c42749ed3 100644 --- a/doc/Installation/Installation-(RHEL-CentOS).md +++ b/doc/Installation/Installation-(RHEL-CentOS).md @@ -51,6 +51,11 @@ Note if not using HTTPd (Apache): RHEL requires `httpd` to be installed regardle pear install Net_IPv4-1.3.4 pear install Net_IPv6-1.2.2b2 +### Adding the librenms-user ### + + useradd librenms -d /opt/librenms -M -r + usermod -a -G librenms www-data + ### Using HTTPd (Apache2) ### Set `httpd` to start on system boot. @@ -167,9 +172,14 @@ First, create and chown the `rrd` directory and create the `logs` directory mkdir rrd logs # For HTTPd (Apache): - chown apache:apache rrd/ + chown apache:apache logs # For Nginx: - chown nginx:nginx rrd/ + chown nginx:nginx logs + + chmod 775 rrd + chown librenms:librenms rrd + +> If you're planing on running rrdcached, make sure that the path is also chmod'ed to 775 and chown'ed to librenms:librenms. Start the web-server: @@ -202,7 +212,7 @@ If the thread count needs to be changed, you can do so by editing the cron file Create the cronjob - cp librenms.cron /etc/cron.d/librenms + cp librenms.nonroot.cron /etc/cron.d/librenms ### Daily Updates ### diff --git a/doc/Installation/Installation-Lighttpd-(Debian-Ubuntu).md b/doc/Installation/Installation-Lighttpd-(Debian-Ubuntu).md index 0e14d7230..4bf0895fd 100644 --- a/doc/Installation/Installation-Lighttpd-(Debian-Ubuntu).md +++ b/doc/Installation/Installation-Lighttpd-(Debian-Ubuntu).md @@ -39,6 +39,11 @@ Install necessary software. The packages listed below are an all-inclusive list apt-get install lighttpd php5-cli php5-mysql php5-gd php5-snmp php5-cgi php-pear php5-curl snmp graphviz mysql-server mysql-client rrdtool sendmail fping imagemagick whois mtr-tiny nmap ipmitool php5-mcrypt php5-json python-mysqldb snmpd php-net-ipv4 php-net-ipv6 rrdtool git +### Adding the librenms-user ### + + useradd librenms -d /opt/librenms -M -r + usermod -a -G librenms www-data + ### Cloning ### You can clone the repository via HTTPS or SSH. In either case, you need to ensure the appropriate port (443 for HTTPS, 22 for SSH) is open in the outbound direction for your server. @@ -81,7 +86,11 @@ To prepare the web interface (and adding devices shortly), you'll need to set up First, create and chown the `rrd` directory and create the `logs` directory mkdir rrd logs - chown www-data:www-data rrd/ + chown www-data:www-data logs + chmod 775 rrd + chown librenms:librenms rrd + +> NOTE: If you're planing on running rrdcached, make sure that the path is also chmod'ed to 775 and chown'ed to librenms:librenms. Next, add the following to `/etc/lighttpd/librenms.conf` @@ -145,7 +154,7 @@ If the thread count needs to be changed, you can do so by editing the cron file Create the cronjob - cp librenms.cron /etc/cron.d/librenms + cp librenms.nonroot.cron /etc/cron.d/librenms ### Daily Updates ### diff --git a/includes/definitions.inc.php b/includes/definitions.inc.php index d9e002bb4..a50f276f0 100644 --- a/includes/definitions.inc.php +++ b/includes/definitions.inc.php @@ -6,6 +6,8 @@ # YES, THAT MEANS YOU # ///////////////////////////////////////////////////////// +umask(0002); + $config['os']['default']['over'][0]['graph'] = "device_processor"; $config['os']['default']['over'][0]['text'] = "Processor Usage"; $config['os']['default']['over'][1]['graph'] = "device_mempool"; diff --git a/includes/functions.php b/includes/functions.php index c66dff623..1e40729b8 100644 --- a/includes/functions.php +++ b/includes/functions.php @@ -240,6 +240,9 @@ function delete_device($id) $ret = ''; $host = dbFetchCell("SELECT hostname FROM devices WHERE device_id = ?", array($id)); + if( empty($host) ) { + return "No such host."; + } foreach (dbFetch("SELECT * FROM `ports` WHERE `device_id` = ?", array($id)) as $int_data) { @@ -260,7 +263,11 @@ function delete_device($id) } } - shell_exec("rm -rf ".trim($config['rrd_dir'])."/$host"); + $ex = shell_exec("bash -c '( [ ! -d ".trim($config['rrd_dir'])."/".$host." ] || rm -vrf ".trim($config['rrd_dir'])."/".$host." 2>&1 ) && echo -n OK'"); + $tmp = explode("\n",$ex); + if( $tmp[sizeof($tmp)-1] != "OK" ) { + $ret .= "Could not remove files:\n$ex\n"; + } $ret .= "Removed device $host\n"; return $ret; diff --git a/librenms.cron b/librenms.cron index 49f74898d..8ea97492c 100644 --- a/librenms.cron +++ b/librenms.cron @@ -1,3 +1,5 @@ +# It's recommended not to run this cron anymore - please see librenms.nonroot.cron + 33 */6 * * * root /opt/librenms/discovery.php -h all >> /dev/null 2>&1 */5 * * * * root /opt/librenms/discovery.php -h new >> /dev/null 2>&1 */5 * * * * root /opt/librenms/poller-wrapper.py 16 >> /dev/null 2>&1 diff --git a/librenms.nonroot.cron b/librenms.nonroot.cron new file mode 100644 index 000000000..7c0fdfc58 --- /dev/null +++ b/librenms.nonroot.cron @@ -0,0 +1,7 @@ +# Using this cron file requires an additional user on your system, please see install docs. + +33 */6 * * * librenms /opt/librenms/discovery.php -h all >> /dev/null 2>&1 +*/5 * * * * librenms /opt/librenms/discovery.php -h new >> /dev/null 2>&1 +*/5 * * * * librenms /opt/librenms/poller-wrapper.py 16 >> /dev/null 2>&1 +15 0 * * * librenms sh /opt/librenms/daily.sh >> /dev/null 2>&1 +* * * * * librenms /opt/librenms/alerts.php >> /dev/null 2>&1