File openstack-monasca-log-metrics.spec of Package openstack-monasca-log-metrics
# 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 username %{sname}
%define groupname logstash
%define mlm_cfg_dir %{_sysconfdir}/%{sname}
%define mlm_log_dir /var/log/%{sname}
%define sname monasca-log-metrics
Name: openstack-%{sname}
Version: 0.0.1
Release: 0
BuildRoot: %{_tmppath}/%{name}-%{version}-build
Url: https://github.com/FujitsuEnablingSoftwareTechnologyGmbH/
Source0: %{name}.logrotate
Source1: %{sname}.conf.sample
Source2: %{name}.service
Summary: Transforms logs into metrics
License: Apache-2.0
Group: Monitoring/Tools
BuildRequires: logstash >= 2.3.0
Requires: logstash >= 2.3.0
Requires: logrotate
Provides: sname
BuildArch: noarch
%description
monasca-log-metrics is a logstash based component whose main task
is to generate metrics from each log according to log severity.
In essence that allows to track count of logs in given severity.
%prep
# no-op
%build
# no-op
%install
# etc
%{__install} -D -m 644 %{S:0} %{buildroot}%{_sysconfdir}/logrotate.d/%{name}
%{__install} -D -m 644 %{S:1} %{buildroot}%{mlm_cfg_dir}/%{sname}.conf.sample
# var
%{__install} -d -m 750 %{buildroot}%{mlm_log_dir}
# service file
%{__install} -D -m 644 %{S:2} %{buildroot}%{_unitdir}/%{name}.service
mkdir -p %{buildroot}%{_sbindir}
ln -s /usr/sbin/service %{buildroot}%{_sbindir}/rc%{name}
# sedding...;)
sed -e "
s|__MLM_USER__|%{username}|g;
s|__MLM_GROUP__|%{groupname}|g;
s|__MLM_CONFIG__|%{mlm_cfg_dir}/%{sname}.conf|g;
s|__MLM_LOGDIR__|%{mlm_log_dir}|g;
" -i %{buildroot}%{_unitdir}/%{name}.service
sed -e "
s|__MLM_USER__|%{username}|g;
s|__MLM_GROUP__|%{groupname}|g;
s|__MLM_LOGDIR__|%{mlm_log_dir}|g;
" -i %{buildroot}%{_sysconfdir}/logrotate.d/%{name}
%pre
groupadd --system %{groupname} 2> /dev/null || :
useradd -r -g %{groupname} \
-d %{_localstatedir}/lib/%{sname} \
-s /sbin/nologin \
-c "user for %{name} service" %{username} 2> /dev/null || :
%service_add_pre %{name}.service
%post
%service_add_post %{name}.service
cat <<EOF
================================================================================
In order to start transforming logs to metrics, following configuration bits
needs to be established:
1) zookeeper nodes addresses
2) kafka brokers addresses
3) name of the topic, monasca-log-transformer sends logs to
4) name of the topic, metrics are sent to from monasca-api
Copy sample file to the correct location and make your changes:
1) cp %{mlm_cfg_dir}/%{sname}.conf.sample %{mlm_cfg_dir}/%{sname}.conf
2) vi %{mlm_cfg_dir}/%{sname}.conf
================================================================================
EOF
%preun
%service_del_preun %{name}.service
%postun
%service_del_postun %{name}.service
if [ $1 -eq 0 ] ; then
getent password %{username} > /dev/null
if [ "$?" == "0" ] ; then
userdel %{username}
fi
fi
%files
%defattr(-,root,root)
%{_unitdir}/%{name}.service
%{_sbindir}/rc%{name}
%dir %{mlm_cfg_dir}
%attr(750,%{username},%{groupname}) %dir %{mlm_log_dir}
%config(noreplace) %{mlm_cfg_dir}/%{sname}.conf.sample
%config(noreplace) %{_sysconfdir}/logrotate.d/%{name}
%changelog