<?xml version="1.0"?>
<!DOCTYPE service_bundle SYSTEM "/usr/share/lib/xml/dtd/service_bundle.dtd.1">
<!--
    Copyright 2021 Jens Elkner.
-->

<service_bundle type='manifest' name='LNFvictoria-metrics:vmalert'>

<service name='application/database/vmalert' type='service' version='1'>

	<instance name="vmalert" enabled="false">

	<!-- Wait for network interfaces to be initialized.  -->
	<dependency name='network' grouping='require_all' restart_on='refresh'
	    type='service'>
	    <service_fmri value='svc:/milestone/network:default'/>
	</dependency>

	<!-- Wait for all local filesystems to be mounted.  -->
	<dependency name='filesystem-local' grouping='require_all' restart_on='none'
	    type='service'>
	    <service_fmri value='svc:/system/filesystem/local:default'/>
	</dependency>

	<exec_method type='method' name='start'
		exec='/usr/sbin/vmalert %{config/start_args} --rule=%{config/rules_dir} --datasource.url=%{config/datasource} --notifier.url=%{config/notify} --evaluationInterval=%{config/interval}'
		timeout_seconds='60'>
		<method_context>
			<method_credential user='daemon' group='daemon' />
			<!-- doesn't hurt if not used (24K) -->
			<method_environment>
				<envvar name='LD_PRELOAD' value='libmtmalloc.so'/>
			</method_environment>
		</method_context>
	</exec_method>

	<exec_method timeout_seconds='10' type='method' name='stop'
		exec=':kill -TERM' />

	<property_group name='config' type='application'>
		<stability value='Evolving' />
		<!-- The directory containing all rule files (*.yml) to use with this
			vmalert instance. You may add others using the -rule="..." option
			in the start_args property.
			The directory must exist, otherwise the service gets not started.
		-->
		<propval name='rules_dir' type='astring' value='/etc/vmalert' />
		<!-- The URL of the PromQL compatible datasource to query periodically.
		-->
		<propval name='datasource' type='astring'
			value='http://localhost:8428' />
		<!-- The default query interval. -->
		<propval name='interval' type='astring' value='5s' />
		<!-- The URL of the alert manager to notify. Additional URLs might be
			added using the -notifier.url="..." option in the start_args
			property.
		-->
		<propval name='notify' type='astring' value='http://localhost:9093' />
		<!--
Any options to pass verbatim to the agent. See 'vmalert -h'.
E.g. if you run multiple vmalert services for the same datastore or
AlertManager - do not forget to specify different -external.label="..."
options in order to define which vmalert generated rules or alerts.
		-->
		<property name="start_args" type="astring">
			<astring_list>
			</astring_list>
		</property>
	</property_group>

	<property_group name='startd' type='framework'>
		<!-- golang bloat usually has no daemon mode =8-( -->
		<propval name='duration' type='astring' value='child' />
		<propval name='ignore_error' type='astring' value='signal' />
	</property_group>

	<!--
		Add all users, which should be able to manage this service
		into /etc/user_attr . E.g.:
		echo 'jdoe::::auths=solaris.smf.manage.vmdb' >>/etc/user_attr
	-->
	<property_group name='general' type='framework'>
		<propval name='action_authorization' type='astring'
			value='solaris.smf.manage.vmalert' />
		<propval name='value_authorization' type='astring'
			value='solaris.smf.manage.vmalert' />
	</property_group>

	<stability value='Evolving' />

	<template>
		<common_name>
			<loctext xml:lang='C'>
				Victoria Metrics alert service
			</loctext>
		</common_name>
		<documentation>
			<doc_link name='vmalert'
				uri='https://docs.victoriametrics.com/vmalert.html' />
		</documentation>
	</template>

	</instance>

	<stability value='Evolving' />
</service>

</service_bundle>
