File snmptt.spec of Package snmptt

#
# spec file for package snmptt
#
# Copyright (c) 2020 SUSE LLC
#
# All modifications and additions to the file contributed by third parties
# remain the property of their copyright owners, unless otherwise agreed
# upon. The license for this file, and modifications and additions to the
# file, is the same license as for the pristine package itself (unless the
# license for the pristine package is not an Open Source License, in which
# case the license is the MIT License). An "Open Source License" is a
# license that conforms to the Open Source Definition (Version 1.9)
# published by the Open Source Initiative.

# Please submit bugfixes or comments via https://bugs.opensuse.org/
#


%define         snmptt_user  _snmptt
%define         snmptt_group _snmptt

%if 0%{?suse_version} >= 1230
%bcond_without systemd
%else
%bcond_with systemd
%endif

Name:           snmptt
Version:        1.4.2
Release:        0
Summary:        SNMP Trap Translator
License:        GPL-2.0-only
Group:          Productivity/Networking/Other
URL:            http://www.snmptt.org/
Source0:        %{name}_%{version}.tar.bz2
Source1:        %{name}.init-suse
Source2:        %{name}-rpmlintrc
Source3:        snmptt.sql
Source4:        snmptt.service
Source5:        snmptt.tmpfiles
Patch1:         snmptt_default_user_and_pidfile.patch
BuildRequires:  help2man
BuildRequires:  perl(Config::IniFiles)
BuildRequires:  perl(SNMP)
Requires:       net-snmp
Requires:       perl
Requires:       perl(Config::IniFiles)
Requires:       perl(File::Basename)
Requires:       perl(File::Spec)
Requires:       perl(Getopt::Long)
Requires:       perl(SNMP)
Requires:       perl(Sys::Hostname)
Requires:       perl(Text::Balanced)
Requires:       perl(Text::ParseWords)
Requires:       perl(Time::HiRes)
Recommends:     perl(DBD::mysql)
BuildArch:      noarch
%if %{with systemd}
BuildRequires: systemd-rpm-macros
%{?systemd_ordering}
%endif
Recommends:     logrotate
BuildRoot:      %{_tmppath}/%{name}-%{version}-build


%description
SNMPTT (SNMP Trap Translator) is an SNMP trap handler written in Perl for use
with the Net-SNMP / UCD-SNMP snmptrapd program (www.net-snmp.org). SNMPTT
supports Linux, Unix and Windows.

Many network devices including but not limited to network switches, routers,
remote access servers, UPSs, printers and operating systems such as Unix and
Windows NT have the ability to send notifications to an SNMP manager running on
a network management station. The notifications can be either SNMP Traps, or
SNMP Inform messages.

The notification can contain a wide array of information such as port failures,
link failures, access violations, power outages, paper jams, hard drive
failures etc. The MIB (Management Information Base) available from the vendor
determines the notifications supported by each device.

The MIB file contains TRAP-TYPE (SMIv1) or NOTIFICATION-TYPE (SMIv2)
definitions, which define the variables that are passed to the management
station when a particular event occurs.

The Net-SNMP program snmptrapd is an application that receives and logs SNMP
trap and inform messages via TCP/IP.

%prep
%setup -q -n %{name}_%{version}
%patch1 -p1
install -m644 %{SOURCE3} snmptt.sql

%build

%install
install -d -m0755 %{buildroot}%{_var}/spool/snmptt

install -Dm0755 snmptt %{buildroot}%{_sbindir}/snmptt
install -m0755 snmpttconvert %{buildroot}%{_sbindir}/
install -m0755 snmpttconvertmib %{buildroot}%{_sbindir}/
install -m0755 snmptthandler %{buildroot}%{_sbindir}/
install -m0755 snmptt-net-snmp-test %{buildroot}%{_sbindir}/

mkdir -p %{buildroot}%{_mandir}/man1
pushd %{buildroot}%{_sbindir}
for file in  * ; do
 case $file in
   snmpttconvert)
   ;;
   *)
    %if 0%{?suse_version} <= 1130
      help2man --name=$file --output=%{buildroot}%{_mandir}/man1/${file}.1 ./$file --help-option=-h
    %else
    	%if 0%{?suse_version} >= 1230
        	help2man --name=$file --output=%{buildroot}%{_mandir}/man1/${file}.1 ./$file --help-option=-h --version-string=%{version} --no-discard-stderr
        %else
      		help2man --name=$file --output=%{buildroot}%{_mandir}/man1/${file}.1 ./$file --help-option=-h --version-string=%{version}
        %endif
    %endif
   ;;
  esac
done
popd

install -m0755 snmptthandler-embedded %{buildroot}%{_sbindir}/

install -d %{buildroot}%{_var}/log/snmptt
install -Dm644 snmptt.logrotate %{buildroot}%{_sysconfdir}/logrotate.d/snmptt
sed -i -e "s|weekly|weekly\n    compress\n    su %{snmptt_user} %{snmptt_group}|g" %{buildroot}%{_sysconfdir}/logrotate.d/snmptt
%if %{with systemd}
sed -i -e "s@/etc/init.d/snmptt reload >/dev/null 2>/dev/null || true@/usr/bin/systemctl reload snmptt.service >/dev/null 2>&1 || true@g" %{buildroot}%{_sysconfdir}/logrotate.d/snmptt
%endif
install -Dm0640 snmptt.ini %{buildroot}%{_sysconfdir}/snmp/snmptt.ini
install -m644 examples/snmptt.conf.generic %{buildroot}%{_sysconfdir}/snmp/snmptt.conf
mkdir -p %{buildroot}%{_sysconfdir}/snmp/snmptt
%if %{with systemd}
install -D -m0644 %{SOURCE4} %{buildroot}%{_unitdir}/%{name}.service
install -D -m0644 %{SOURCE5} %{buildroot}%{_prefix}/lib/tmpfiles.d/%{name}.conf
ln -sf /usr/sbin/service %{buildroot}%{_sbindir}/rcsnmptt
%else
install -Dm744 %{SOURCE1} %{buildroot}%{_sysconfdir}/init.d/snmptt
ln -sf ../..%{_initddir}/snmptt %{buildroot}%{_sbindir}/rcsnmptt
%endif

%pre
if
    getent group %{snmptt_group} >/dev/null
then
    : OK group %{snmptt_group} already present
else
    groupadd -r %{snmptt_group} 2>/dev/null || :
fi
if
    id %{snmptt_user} > /dev/null 2>&1
then
    : OK user %{snmptt_user} already present
else
    useradd  -r -g %{snmptt_group} -s /bin/false -c "SNMP Trap Translator Daemon" -d %{_var}/spool/snmptt %{snmptt_user} 2> /dev/null || :
fi
%if %{with systemd}
%service_add_pre %{name}.service
%endif

%post
%if %{with systemd}
%service_add_post %{name}.service
systemd-tmpfiles --create %{_prefix}/lib/tmpfiles.d/%{name}.conf
%fillup_only
%else
%{fillup_and_insserv snmptt}
%endif

%preun
%if %{with systemd}
%service_del_preun %{name}.service
%else
%stop_on_removal snmptt
%endif

%postun
%if %{with systemd}
%service_del_postun %{name}.service
%else
%restart_on_update snmptt
%insserv_cleanup
%endif

%files
%defattr(-,root,root)
%license COPYING
%doc docs/ examples contrib/ sample-trap BUGS ChangeLog README snmptt.sql
%dir %{_sysconfdir}/snmp
%dir %{_sysconfdir}/snmp/%{name}
%attr(0755,%{snmptt_user},%{snmptt_group}) %dir %{_var}/log/snmptt
%attr(0755,%{snmptt_user},%{snmptt_group}) %dir %{_var}/spool/snmptt
%attr(0640,root,%{snmptt_group}) %config(noreplace) %{_sysconfdir}/snmp/snmptt.ini
%config(noreplace) %{_sysconfdir}/snmp/snmptt.conf
%config(noreplace) %{_sysconfdir}/logrotate.d/snmptt
%{_mandir}/man1/*
%if %{with systemd}
%{_unitdir}/%{name}.service
%{_prefix}/lib/tmpfiles.d/%{name}.conf
%ghost %dir /run/snmptt
%else
%{_sysconfdir}/init.d/snmptt
%endif
%{_sbindir}/*

%changelog
openSUSE Build Service is sponsored by