<?xml version="1.0" encoding="utf-8" ?>
<feed xmlns="http://www.w3.org/2005/Atom">
<title>Fun with ones and zeros - systemd</title>
<subtitle>Barry&#039;s notes on computer software and hardware</subtitle>
<link href="/blog/tags/systemd"></link>
<updated>2026-04-30T02:44:36-07:00</updated>
<id>urn:uuid:0648bdbc-a49b-26a1-33f4-d9956ceee922</id>
<entry>
<title>Decrease snmpd logging level on Ubuntu 18.04</title>
<link href="/blog/entries/decrease-snmpd-logging-on-ubuntu-18-04"></link>
<id>urn:uuid:f8795ac9-fdc7-866a-08df-795aa674e222</id>
<updated>2020-03-01T08:45:00-08:00</updated>
<author><name>Barry Pederson</name>
<email>bp@barryp.org</email>
</author>
<content type="html">&lt;body&gt;&lt;p&gt;I recently updated some servers from Ubuntu 16.04 to 18.04, and found that
the &lt;code&gt;snmpd&lt;/code&gt; daemon was generating way too many log entries
in &lt;code&gt;/var/log/syslog&lt;/code&gt; - one for every SNMP query coming from our monitoring system.  &lt;/p&gt;
&lt;p&gt;In older Ubuntus I had edited &lt;code&gt;/etc/defaults/snmpd&lt;/code&gt; to change the &lt;code&gt;SNMPDOPTS&lt;/code&gt; line
to have a different &lt;code&gt;-Ls&lt;/code&gt; parameter, but it seems that on the new Ubuntu, the
systemd service for snmp doesn&#039;t use that &lt;code&gt;defaults&lt;/code&gt; file at all.  A comment
on this &lt;a href=&quot;https://serverfault.com/questions/310640/reduce-snmpd-logging-verbosity&quot;&gt;serverfault question&lt;/a&gt;
gave me a clue on how to fix it in systemd - I thought I&#039;d elaborate here.&lt;/p&gt;
&lt;p&gt;If you run &lt;/p&gt;
&lt;pre&gt;&lt;code&gt;systemctl cat snmpd.service&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;You see the current service file:&lt;/p&gt;
&lt;div class=&quot;source&quot;&gt;&lt;pre&gt;&lt;span&gt;&lt;/span&gt;&lt;span class=&quot;c1&quot;&gt;# /lib/systemd/system/snmpd.service&lt;/span&gt;
&lt;span class=&quot;k&quot;&gt;[Unit]&lt;/span&gt;
&lt;span class=&quot;na&quot;&gt;Description&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;Simple Network Management Protocol (SNMP) Daemon.&lt;/span&gt;
&lt;span class=&quot;na&quot;&gt;After&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;network.target&lt;/span&gt;
&lt;span class=&quot;na&quot;&gt;ConditionPathExists&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;/etc/snmp/snmpd.conf&lt;/span&gt;

&lt;span class=&quot;k&quot;&gt;[Service]&lt;/span&gt;
&lt;span class=&quot;na&quot;&gt;Environment&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;MIBSDIR=/usr/share/snmp/mibs:/usr/share/snmp/mibs/iana:/usr/share/snmp/mibs/ietf:/usr/share/mibs/site:/usr/share/snmp/mibs:/usr/share/mibs/iana:/usr/share/mibs/ietf:/usr/share/mibs/netsnmp&quot;&lt;/span&gt;
&lt;span class=&quot;na&quot;&gt;Environment&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;MIBS=&quot;&lt;/span&gt;
&lt;span class=&quot;na&quot;&gt;Type&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;simple&lt;/span&gt;
&lt;span class=&quot;na&quot;&gt;ExecStartPre&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;/bin/mkdir -p /var/run/agentx&lt;/span&gt;
&lt;span class=&quot;na&quot;&gt;ExecStart&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;/usr/sbin/snmpd -Lsd -Lf /dev/null -u Debian-snmp -g Debian-snmp -I -smux,mteTrigger,mteTriggerConf -f&lt;/span&gt;
&lt;span class=&quot;na&quot;&gt;ExecReload&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;/bin/kill -HUP $MAINPID&lt;/span&gt;

&lt;span class=&quot;k&quot;&gt;[Install]&lt;/span&gt;
&lt;span class=&quot;na&quot;&gt;WantedBy&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;multi-user.target&lt;/span&gt;
&lt;/pre&gt;&lt;/div&gt;
&lt;p&gt;I wanted to override the ExecStart line with something different.  To do that, run&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;systemctl edit snmpd.service&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;This brings up your default editor with a &lt;em&gt;blank&lt;/em&gt; file.  I entered these new lines:&lt;/p&gt;
&lt;div class=&quot;source&quot;&gt;&lt;pre&gt;&lt;span&gt;&lt;/span&gt;&lt;span class=&quot;c1&quot;&gt;# Override default &quot;-Lsd&quot; paramter to &quot;-LSwd&quot; to decrease logging level&lt;/span&gt;
&lt;span class=&quot;k&quot;&gt;[Service]&lt;/span&gt;
&lt;span class=&quot;na&quot;&gt;ExecStart&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;
&lt;span class=&quot;na&quot;&gt;ExecStart&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;/usr/sbin/snmpd -LSwd -Lf /dev/null -u Debian-snmp -g Debian-snmp -I -smux,mteTrigger,mteTriggerConf -f&lt;/span&gt;
&lt;/pre&gt;&lt;/div&gt;
&lt;p&gt;The first &lt;code&gt;ExecStart=&lt;/code&gt; line is a bit odd, without it you get an error:&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;snmpd.service: Service has more than one ExecStart= setting, which is only allowed for Type=oneshot services. Refusing.&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;so the first line &#039;clears&#039; the setting before processing your own version.&lt;/p&gt;
&lt;p&gt;Save your file (&lt;code&gt;systemctl edit&lt;/code&gt; stores it as &lt;code&gt;/etc/systemd/system/snmpd.service.d/override.conf&lt;/code&gt;), and then run
&lt;code&gt;service snmpd restart&lt;/code&gt; to have take effect. If you re-run &lt;code&gt;systemctl cat snmpd.service&lt;/code&gt; you should now see:&lt;/p&gt;
&lt;div class=&quot;source&quot;&gt;&lt;pre&gt;&lt;span&gt;&lt;/span&gt;&lt;span class=&quot;c1&quot;&gt;# /lib/systemd/system/snmpd.service&lt;/span&gt;
&lt;span class=&quot;k&quot;&gt;[Unit]&lt;/span&gt;
&lt;span class=&quot;na&quot;&gt;Description&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;Simple Network Management Protocol (SNMP) Daemon.&lt;/span&gt;
&lt;span class=&quot;na&quot;&gt;After&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;network.target&lt;/span&gt;
&lt;span class=&quot;na&quot;&gt;ConditionPathExists&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;/etc/snmp/snmpd.conf&lt;/span&gt;

&lt;span class=&quot;k&quot;&gt;[Service]&lt;/span&gt;
&lt;span class=&quot;na&quot;&gt;Environment&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;MIBSDIR=/usr/share/snmp/mibs:/usr/share/snmp/mibs/iana:/usr/share/snmp/mibs/ietf:/usr/share/mibs/site:/usr/share/snmp/mibs:/usr/share/mibs/iana:/usr/share/mibs/ietf:/usr/share/mibs/netsnmp&quot;&lt;/span&gt;
&lt;span class=&quot;na&quot;&gt;Environment&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;MIBS=&quot;&lt;/span&gt;
&lt;span class=&quot;na&quot;&gt;Type&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;simple&lt;/span&gt;
&lt;span class=&quot;na&quot;&gt;ExecStartPre&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;/bin/mkdir -p /var/run/agentx&lt;/span&gt;
&lt;span class=&quot;na&quot;&gt;ExecStart&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;/usr/sbin/snmpd -Lsd -Lf /dev/null -u Debian-snmp -g Debian-snmp -I -smux,mteTrigger,mteTriggerConf -f&lt;/span&gt;
&lt;span class=&quot;na&quot;&gt;ExecReload&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;/bin/kill -HUP $MAINPID&lt;/span&gt;

&lt;span class=&quot;k&quot;&gt;[Install]&lt;/span&gt;
&lt;span class=&quot;na&quot;&gt;WantedBy&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;multi-user.target&lt;/span&gt;

&lt;span class=&quot;c1&quot;&gt;# /etc/systemd/system/snmpd.service.d/override.conf&lt;/span&gt;
&lt;span class=&quot;c1&quot;&gt;# Override default &quot;-Lsd&quot; paramter to &quot;-LSwd&quot; to decrease logging level&lt;/span&gt;
&lt;span class=&quot;k&quot;&gt;[Service]&lt;/span&gt;
&lt;span class=&quot;na&quot;&gt;ExecStart&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;
&lt;span class=&quot;na&quot;&gt;ExecStart&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;/usr/sbin/snmpd -LSwd -Lf /dev/null -u Debian-snmp -g Debian-snmp -I -smux,mteTrigger,mteTriggerConf -f&lt;/span&gt;
&lt;/pre&gt;&lt;/div&gt;
&lt;p&gt;Which is a combination of the default service along with your override.&lt;/p&gt;
&lt;p&gt;If you have other servers you want to copy your &lt;code&gt;/etc/systemd/system/snmpd.service.d/override.conf&lt;/code&gt; file to, you need
to run&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;systemctl daemon-reload
service snmpd restart&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;to have it take effect.&lt;/p&gt;&lt;/body&gt;</content>
</entry>
</feed>