1# Copyright 2021 Northern.tech AS 2 3# This file is part of CFEngine 3 - written and maintained by Northern.tech AS. 4 5# This program is free software; you can redistribute it and/or modify it 6# under the terms of the GNU General Public License as published by the 7# Free Software Foundation; version 3. 8 9# This program is distributed in the hope that it will be useful, 10# but WITHOUT ANY WARRANTY; without even the implied warranty of 11# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12# GNU General Public License for more details. 13 14# You should have received a copy of the GNU General Public License 15# along with this program; if not, write to the Free Software 16# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA 17 18# To the extent this program is licensed as part of the Enterprise 19# versions of Cfengine, the applicable Commercial Open Source License 20# (COSL) may apply to this file if you as a licensee so wish it. See 21# included file COSL.txt. 22 23#+begin_src cfengine3 24body common control 25{ 26 bundlesequence => { "test" }; 27} 28 29bundle agent test 30{ 31 vars: 32 # the behavior will be the same whether you use a data container or a list 33 # "mylist" slist => { "foo", "1", "2", "3000", "bar", "10.20.30.40" }; 34 "mylist" data => parsejson('["foo", "1", "2", "3000", "bar", "10.20.30.40"]'); 35 "mylist_str" string => format("%S", mylist); 36 37 "max_int" string => max(mylist, "int"); 38 "max_lex" string => max(mylist, "lex"); 39 "max_ip" string => max(mylist, "ip"); 40 41 "min_int" string => min(mylist, "int"); 42 "min_lex" string => min(mylist, "lex"); 43 "min_ip" string => min(mylist, "ip"); 44 45 "mean" real => mean(mylist); 46 "variance" real => variance(mylist); 47 48 reports: 49 "my list is $(mylist_str)"; 50 51 "mean is $(mean)"; 52 "variance is $(variance) (use eval() to get the standard deviation)"; 53 54 "max int is $(max_int)"; 55 "max IP is $(max_ip)"; 56 "max lexicographically is $(max_lex)"; 57 58 "min int is $(min_int)"; 59 "min IP is $(min_ip)"; 60 "min lexicographically is $(min_lex)"; 61} 62#+end_src 63############################################################################### 64#+begin_src example_output 65#@ ``` 66#@ R: my list is ["foo","1","2","3000","bar","10.20.30.40"] 67#@ R: mean is 502.200000 68#@ R: variance is 1497376.000000 (use eval() to get the standard deviation) 69#@ R: max int is 3000 70#@ R: max IP is 10.20.30.40 71#@ R: max lexicographically is foo 72#@ R: min int is bar 73#@ R: min IP is 1 74#@ R: min lexicographically is 1 75#@ ``` 76#+end_src 77