Hi Team,
On the LibreNMS server itself (used the CentOS 7 vmdk downloadable on the LibreNMS site), I have this:
# yum check-update
Loaded plugins: fastestmirror
Loading mirror speeds from cached hostfile
* base: mirrors.lga7.us.voxel.net
* epel: mirror.math.princeton.edu
* extras: repo1.ash.innoscale.net
* updates: mirrors.centos.webair.com
* webtatic: us-east.repo.webtatic.com
dnsmasq.x86_64 2.76-2.el7_4.2 updates
nss.x86_64 3.28.4-12.el7_4 updates
nss-sysinit.x86_64 3.28.4-12.el7_4 updates
nss-tools.x86_64 3.28.4-12.el7_4 updates
yet:
# /etc/snmp/os-updates.sh
0
It should be 4 right?
Michael.
that looks right…
Not sure what exactly you are asking tho.
Hi Kevin. The server shows there are 4 updates, through the “yum check-update” output.
Conversely, the os-updates script shows there are 0 updates.
So the script is wrong?
Michael.
laf
4 October 2017 18:58
4
it runs yum -q check-update | wc -l
- what does that return.
Hi laf,
What I get:
# yum check-update
Loaded plugins: fastestmirror
Loading mirror speeds from cached hostfile
* base: mirror.cc.columbia.edu
* epel: mirror.us.leaseweb.net
* extras: mirror.datto.com
* updates: mirror.cogentco.com
* webtatic: us-east.repo.webtatic.com
dnsmasq.x86_64 2.76-2.el7_4.2 updates
nss.x86_64 3.28.4-12.el7_4 updates
nss-sysinit.x86_64 3.28.4-12.el7_4 updates
nss-tools.x86_64 3.28.4-12.el7_4 updates
# /etc/snmp/os-updates.sh
0
# yum -q check-update | wc -l
5
So definitely something wrong there. Even the last command should return 4, not 5.
Michael.
I don’t have much CentOS outside of a couple test VM’s so I’m not completely sure but I’m guessing the output of yum -q might have been recently cleaned up? It looks to me like the script is expecting 6 lines of junk so it outputs 0 if the line count is 6 or less.
It seems like now if there are no updates wc -l is 0. If there are updates it is the # of updates + 1 (single blank line above the first package).
# yum -q check-update
dnsmasq.x86_64 2.76-2.el7_4.2 updates
nss.x86_64 3.28.4-12.el7_4 updates
nss-sysinit.x86_64 3.28.4-12.el7_4 updates
nss-tools.x86_64 3.28.4-12.el7_4
#
Maybe as a test try editing the centos section of your os-updates.sh to…
elif [ $OS == "\"centos\"" ]; then
UPDATES=`$BIN_YUM $CMD_YUM | $BIN_WC $CMD_WC`
if [ $UPDATES -gt 1 ]; then
echo $(($UPDATES-1));
else
echo "0";
fi
Hi,
I made that edit to the os-updates.sh script as requested.
Testing:
# yum -q check-update
dnsmasq.x86_64 2.76-2.el7_4.2 updates
nss.x86_64 3.28.4-12.el7_4 updates
nss-sysinit.x86_64 3.28.4-12.el7_4 updates
nss-tools.x86_64 3.28.4-12.el7_4 updates
# /etc/snmp/os-updates.sh
4
Seems quite correct to me now. Good work.
I’ll try this change on some other CentOS boxes too, to make sure it is fool-proof.
Thanks.
Michael.
if all this works…yall may want to make a pull request in git hub to make those changes to that script for everyone
@slashdoom
laf
5 October 2017 19:02
9
Be worth checking on centos 6 and 5. This update works on 7 fine for me.
I wouldn’t expect this script to work at all on CentOS 6 due to the dependancy on /etc/os-release. Looking back at the history of this script it looks like at one point @murrant made a nice change that made the script look for package managers rather than OS version that would have fixed both issues here. It looks like this was completely reverted in the below PR due to some zypper/apt wrapper issue…
librenms:master
← crcro:snmp-extend-os-updates-update-1
opened 02:09PM - 16 Sep 16 UTC
- reverted back to os-release checks (fix issue: #64)
- added arch pacman suppor… t
I know no nothing about suse distros but I’m wondering if a better fix than reverting would have just been to check for zypper before checking for apt?
2 Likes
It would be great if you sent a pull request on github with the changes you describe.
1 Like
Sure, PR opened as requested…
librenms:master
← slashdoom:master
opened 08:38PM - 06 Oct 17 UTC
Pull request as recommended in community post: https://community.librenms.org/t/… osupdates-on-the-librenms-server-itself/2253/11
- Goes back to package management detection rather than os release.
- zypper checked before apt for OpenSUSE zypper/apt wrapper.
- dnf checked before yum for Fedora version with dnf2yum wrapper.
Tested well on: centos6, centos7, opensuse46, rhel7, fedora24, debian jessie, devuan jessie (both with some updates and with no updates).
2 Likes
Gorian
9 October 2017 21:18
13
Something like this works well enough
#!/usr/bin/env bash
{ #try
OS=$(awk -F"=" '/^ID=/{print $2}' /etc/os-release);
} >/dev/null 2>&1 ||
{ #catch
OS=$(cat /etc/*-release | head -n1);
}
printf "%s\n" "$OS";