Initial commit
diff --git a/CHANGELOG.rst b/CHANGELOG.rst
new file mode 100644
index 0000000..a6ce714
--- /dev/null
+++ b/CHANGELOG.rst
@@ -0,0 +1,6 @@
+ntp formula
+===========
+
+0.0.1 (2015-08-03)
+
+- Initial formula setup
\ No newline at end of file
diff --git a/LICENSE b/LICENSE
new file mode 100644
index 0000000..8e80b12
--- /dev/null
+++ b/LICENSE
@@ -0,0 +1,13 @@
+Copyright (c) 2014-2015 tcp cloud a. s.
+
+Licensed under the Apache License, Version 2.0 (the "License");
+you may not use this file except in compliance with the License.
+You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+Unless required by applicable law or agreed to in writing, software
+distributed under the License is distributed on an "AS IS" BASIS,
+WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+See the License for the specific language governing permissions and
+limitations under the License.
\ No newline at end of file
diff --git a/README.rst b/README.rst
new file mode 100644
index 0000000..85f22f6
--- /dev/null
+++ b/README.rst
@@ -0,0 +1,24 @@
+===
+NTP
+===
+
+Network time synchronisation services.
+
+Sample pillars
+==============
+
+NTP client
+
+.. code-block:: yaml
+
+ ntp:
+ client:
+ enabled: true
+ strata:
+ - ntp.cesnet.cz
+ - ntp.nic.cz
+
+Read more
+=========
+
+* https://collectd.org/wiki/index.php/Plugin:NTPd
diff --git a/VERSION b/VERSION
new file mode 100644
index 0000000..3b04cfb
--- /dev/null
+++ b/VERSION
@@ -0,0 +1 @@
+0.2
diff --git a/debian/changelog b/debian/changelog
new file mode 100644
index 0000000..49f1354
--- /dev/null
+++ b/debian/changelog
@@ -0,0 +1,11 @@
+salt-formula-ntp (0.2) trusty; urgency=medium
+
+ * First public release
+
+ -- Filip Pytloun <filip.pytloun@tcpcloud.eu> Tue, 06 Oct 2015 16:38:49 +0200
+
+salt-formula-ntp (0.1) trusty; urgency=medium
+
+ * Initial release
+
+ -- Ales Komarek <ales.komarek@tcpcloud.eu> Thu, 13 Aug 2015 23:23:41 +0200
diff --git a/debian/compat b/debian/compat
new file mode 100644
index 0000000..ec63514
--- /dev/null
+++ b/debian/compat
@@ -0,0 +1 @@
+9
diff --git a/debian/control b/debian/control
new file mode 100644
index 0000000..9aead51
--- /dev/null
+++ b/debian/control
@@ -0,0 +1,15 @@
+Source: salt-formula-ntp
+Maintainer: Ales Komarek <ales.komarek@tcpcloud.eu>
+Section: admin
+Priority: optional
+Build-Depends: debhelper (>= 9)
+Standards-Version: 3.9.6
+Homepage: http://www.tcpcloud.eu
+Vcs-Browser: https://github.com/tcpcloud/salt-formula-ntp
+Vcs-Git: https://github.com/tcpcloud/salt-formula-ntp.git
+
+Package: salt-formula-ntp
+Architecture: all
+Depends: ${misc:Depends}, salt-master, reclass
+Description: NTP salt formula
+ Install and configure NTP client and server.
diff --git a/debian/copyright b/debian/copyright
new file mode 100644
index 0000000..1cb86f6
--- /dev/null
+++ b/debian/copyright
@@ -0,0 +1,15 @@
+Format: http://www.debian.org/doc/packaging-manuals/copyright-format/1.0/
+Upstream-Name: salt-formula-ntp
+Upstream-Contact: Ales Komarek <ales.komarek@tcpcloud.eu>
+Source: https://github.com/tcpcloud/salt-formula-ntp
+
+Files: *
+Copyright: 2014-2015 tcp cloud a.s.
+License: Apache-2.0
+ Copyright (C) 2014-2015 tcp cloud a.s.
+ .
+ Licensed under the Apache License, Version 2.0 (the "License");
+ you may not use this file except in compliance with the License.
+ .
+ On a Debian system you can find a copy of this license in
+ /usr/share/common-licenses/Apache-2.0.
diff --git a/debian/docs b/debian/docs
new file mode 100644
index 0000000..d585829
--- /dev/null
+++ b/debian/docs
@@ -0,0 +1,3 @@
+README.rst
+CHANGELOG.rst
+VERSION
diff --git a/debian/install b/debian/install
new file mode 100644
index 0000000..0ddf578
--- /dev/null
+++ b/debian/install
@@ -0,0 +1,2 @@
+ntp/* /usr/share/salt-formulas/env/ntp/
+metadata/service/* /usr/share/salt-formulas/reclass/service/ntp/
diff --git a/debian/rules b/debian/rules
new file mode 100755
index 0000000..abde6ef
--- /dev/null
+++ b/debian/rules
@@ -0,0 +1,5 @@
+#!/usr/bin/make -f
+
+%:
+ dh $@
+
diff --git a/debian/source/format b/debian/source/format
new file mode 100644
index 0000000..89ae9db
--- /dev/null
+++ b/debian/source/format
@@ -0,0 +1 @@
+3.0 (native)
diff --git a/metadata/service/client/init.yml b/metadata/service/client/init.yml
new file mode 100644
index 0000000..08881b5
--- /dev/null
+++ b/metadata/service/client/init.yml
@@ -0,0 +1,12 @@
+applications:
+- ntp
+parameters:
+ _param:
+ ntp_strata_host1: ntp.cesnet.cz
+ ntp_strata_host2: ntp.nic.cz
+ ntp:
+ client:
+ enabled: true
+ strata:
+ - ${_param:ntp_strata_host1}
+ - ${_param:ntp_strata_host2}
\ No newline at end of file
diff --git a/ntp/client.sls b/ntp/client.sls
new file mode 100644
index 0000000..2f6084d
--- /dev/null
+++ b/ntp/client.sls
@@ -0,0 +1,54 @@
+{% from "ntp/map.jinja" import client with context %}
+
+{%- if client.enabled %}
+
+{%- if grains.os_family == 'Arch' %}
+
+ntp_remove_packages:
+ pkg.removed:
+ - names:
+ - openntpd
+ - require_in:
+ - pkg: ntp_packages
+
+{%- endif %}
+
+ntp_packages:
+ pkg.installed:
+ - name: ntp
+
+{%- if grains.os_family == "RedHat" %}
+
+ntp_client_group_and_user:
+ group.present:
+ - name: ntp
+ - require:
+ - pkg: ntp_packages
+ user.present:
+ - name: ntp
+ - shell: /sbin/nologin
+ - home: /etc/ntp
+ - groups:
+ - ntp
+ - require:
+ - group: ntp
+ - require_in:
+ - file: /etc/ntp.conf
+
+{%- endif %}
+
+/etc/ntp.conf:
+ file.managed:
+ - source: salt://ntp/files/ntp.conf
+ - template: jinja
+ - require:
+ - pkg: ntp_packages
+
+ntp_service:
+ service.running:
+ - enable: true
+ - name: {{ client.service }}
+ - watch:
+ - file: /etc/ntp.conf
+
+{%- endif %}
diff --git a/ntp/files/collectd.conf b/ntp/files/collectd.conf
new file mode 100644
index 0000000..43325b1
--- /dev/null
+++ b/ntp/files/collectd.conf
@@ -0,0 +1,7 @@
+{%- from "ntp/map.jinja" import server with context %}
+LoadPlugin ntpd
+<Plugin "ntpd">
+ Host "{% if server.bind.address == '0.0.0.0' %}127.0.0.1{% else %}{{ server.bind.address }}{% endif %}"
+ Port "123"
+ ReverseLookups false
+</Plugin>
diff --git a/ntp/files/ntp.conf b/ntp/files/ntp.conf
new file mode 100644
index 0000000..744f094
--- /dev/null
+++ b/ntp/files/ntp.conf
@@ -0,0 +1,31 @@
+{%- set ntp = pillar.ntp.client %}
+
+# ntpd will only synchronize your clock.
+
+# For details, see:
+# - the ntp.conf man page
+# - http://support.ntp.org/bin/view/Support/GettingStarted
+# - https://wiki.archlinux.org/index.php/Network_Time_Protocol_daemon
+
+# Associate to Czech public NTP pool servers
+{%- for stratum in ntp.strata %}
+server {{ stratum }}{% if loop.first %} iburst{% endif %}
+{%- endfor %}
+
+# Provide your current local time as a default should you temporarly lose Internet connectivity
+# server 127.127.1.0
+# fudge 127.127.1.0 stratum 10
+
+# Only allow read-only access from localhost
+restrict default noquery nopeer
+
+# exchange time with everybody, but don't allow configuration.
+#restrict -4 default kod notrap nomodify nopeer noquery
+#restrict -6 default kod notrap nomodify nopeer noquery
+
+restrict 127.0.0.1
+restrict ::1
+
+# Location of drift file
+driftfile /var/lib/ntp/ntp.drift
+logfile /var/log/ntp.log
diff --git a/ntp/files/sensu.conf b/ntp/files/sensu.conf
new file mode 100644
index 0000000..eb84752
--- /dev/null
+++ b/ntp/files/sensu.conf
@@ -0,0 +1,16 @@
+{%- from "ntp/map.jinja" import client with context -%}
+local_ntp_service_proc:
+ command: "PATH=$PATH:/usr/lib64/nagios/plugins:/usr/lib/nagios/plugins check_procs -a '/usr/sbin/ntpd' -u ntp -c 1:1"
+ interval: 300
+ occurrences: 1
+ subscribers:
+ - local-ntp-client
+ - local-ntp-server
+{%- for stratum in client.get('strata', []) %}
+local_ntp_client_time_{{ stratum }}:
+ command: "PATH=:/usr/lib64/nagios/plugins:/usr/lib/nagios/plugins check_ntp_time -q -H {{ stratum }} -w 0.2 -c 2"
+ interval: 3600
+ occurrences: 10
+ subscribers:
+ - local-ntp-client
+{%- endfor %}
\ No newline at end of file
diff --git a/ntp/init.sls b/ntp/init.sls
new file mode 100644
index 0000000..b52343d
--- /dev/null
+++ b/ntp/init.sls
@@ -0,0 +1,8 @@
+
+include:
+{% if pillar.ntp.client is defined %}
+- ntp.client
+{% endif %}
+{% if pillar.ntp.server is defined %}
+- ntp.server
+{% endif %}
diff --git a/ntp/map.jinja b/ntp/map.jinja
new file mode 100644
index 0000000..249eb2f
--- /dev/null
+++ b/ntp/map.jinja
@@ -0,0 +1,24 @@
+
+{% set client = salt['grains.filter_by']({
+ 'Arch': {
+ 'service': 'ntpd',
+ },
+ 'Debian': {
+ 'service': 'ntp',
+ },
+ 'RedHat': {
+ 'service': 'ntpd',
+ },
+}, merge=salt['pillar.get']('ntp:client')) %}
+
+{% set server = salt['grains.filter_by']({
+ 'Arch': {
+ 'service': 'ntpd',
+ },
+ 'Debian': {
+ 'service': 'ntp',
+ },
+ 'RedHat': {
+ 'service': 'ntpd',
+ },
+}, merge=salt['pillar.get']('ntp:server')) %}
diff --git a/ntp/server.sls b/ntp/server.sls
new file mode 100644
index 0000000..a56761e
--- /dev/null
+++ b/ntp/server.sls
@@ -0,0 +1,4 @@
+{%- from "ntp/map.jinja" import server with context %}
+{%- if server.enabled %}
+
+{%- endif %}
\ No newline at end of file