File openstack-monasca-log-agent.spec of Package openstack-monasca-log-agent

#
# spec file for package openstack-monasca-log-agent
#
# Copyright (c) 2017 SUSE LINUX GmbH, Nuernberg, Germany.
# Copyright 2017 Fujitsu LIMITED
#
# 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 http://bugs.opensuse.org/
#


%define mod_name logstash-output-monasca_log_api
%define mod_full_name %{mod_name}-%{version}
%define sname monasca-log-agent

Name:           openstack-%{sname}
Version:        0.5.3
Release:        0
BuildRoot:      %{_tmppath}/%{name}-%{version}-build
Url:            https://github.com/FujitsuEnablingSoftwareTechnologyGmbH/logstash-output-monasca_api
Source:         https://rubygems.org/gems/%{mod_full_name}.gem 
Source1:        %{name}.logrotate
Source2:        %{sname}.conf.sample
Source3:        %{name}.service
Summary:        Collects logs or events via logstash and send them to monasca-log-api
License:        Apache-2.0
Group:          Monitoring/Tools

%if 0%{?suse_version} >= 1210
BuildRequires:  systemd-rpm-macros
%endif
BuildRequires:  logstash >= 2.3.0
Requires:       logrotate
Requires:       logstash >= 2.3.0

BuildArch:      noarch

%description
monasca-log-agent is actually a label for logstash-output-monasca_log_api
and custom configuration file, both of which are used to run
instance of logstash

%prep
# no-op

%build
# no-op

%install

# etc
%{__install} -d -m 755 %{buildroot}%{_sysconfdir}/%{sname}/conf.d
%{__install} -D -m 644 %{S:1} %{buildroot}%{_sysconfdir}/logrotate.d/%{name}
%{__install} -D -m 644 %{S:2} %{buildroot}%{_sysconfdir}/%{sname}/agent.conf.sample

# usr
%{__install} -d -m 755 %{buildroot}/%{_datadir}/%{sname}

# var
%{__install} -d -m 750 %{buildroot}/var/log/%{sname}

# service file
%{__install} -D -m 644 %{S:3} %{buildroot}%{_unitdir}/%{name}.service
mkdir -p %{buildroot}%{_sbindir}
ln -s /usr/sbin/service %{buildroot}%{_sbindir}/rc%{name}

# gem file
%{__install} -D -m 644 %{S:0} %{buildroot}/%{_datadir}/%{sname}/logstash-output-monasca_log_api-0.5.3.gem

%pre
%service_add_pre %{name}.service

%post
%service_add_post %{name}.service
/opt/logstash/bin/logstash-plugin install --local %{_datadir}/%{sname}/logstash-output-monasca_log_api-0.5.3.gem
cat <<EOF

================================================================================
In order to start shipping logs to monasca-log-api you need to copy and edit
/etc/monasca-log-agent/agent.conf.sample.

1) cp /etc/monasca-log-agent/agent.conf.sample /etc/monasca-log-agent/agent.conf
2) vi /etc/monasca-log-agent/agent.conf

and provide:
1) keystone credentials (and url) identyfying user who wishes to send logs
2) monasca-log-api url
3) global dimensions, that will be attached to every log sent, specifically
describing each and one of them.

================================================================================

EOF

%preun
%service_del_preun %{name}.service

%postun
# uninstalling requires NET access
# /opt/logstash/bin/logstash-plugin uninstall logstash-output-monasca_log_api
%service_del_postun %{name}.service
cat <<EOF

================================================================================
Uninstallation of logstash-output-monasca_log_api is not possible without
internet access, which might not be available due to proxy
limitations or simply because it is absent, therefore uninstalltion
cannot be guaranteed. 

You can try removing plugin manually using following command:

/opt/logstash/bin/logstash-plugin uninstall logstash-output-monasca_log_api
================================================================================

EOF

%files
%defattr(-,root,root)

%{_unitdir}/%{name}.service
%{_sbindir}/rc%{name}

%dir %{_sysconfdir}/%{sname}
%dir %{_sysconfdir}/%{sname}/conf.d
%dir %{_datadir}/%{sname}

%config(noreplace) %{_sysconfdir}/%{sname}/agent.conf.sample
%{_datadir}/%{sname}/logstash-output-monasca_log_api-0.5.3.gem

%config(noreplace) %{_sysconfdir}/logrotate.d/%{name}
%dir /var/log/%{sname}

%changelog
openSUSE Build Service is sponsored by