pax_global_header00006660000000000000000000000064135474535670014535gustar00rootroot0000000000000052 comment=ccca50292b7af31d999a88f8bca2aa20bf89f6fc slinkwatch-1.1/000077500000000000000000000000001354745356700135455ustar00rootroot00000000000000slinkwatch-1.1/.circleci/000077500000000000000000000000001354745356700154005ustar00rootroot00000000000000slinkwatch-1.1/.circleci/config.yml000066400000000000000000000012671354745356700173760ustar00rootroot00000000000000# Golang CircleCI 2.0 configuration file # # Check https://circleci.com/docs/2.0/language-go/ for more details version: 2 jobs: build: docker: - image: circleci/golang:1.10-stretch working_directory: /go/src/github.com/DCSO/slinkwatch steps: - checkout - run: name: Add stretch-backports command: 'echo "deb http://ftp.debian.org/debian stretch-backports main" | sudo tee -a /etc/apt/sources.list.d/backports.list' - run: name: Install apt dependencies command: 'sudo apt-get update && sudo apt-get -t stretch-backports install libdaemon-dev libsystemd-dev -y' - run: dep ensure - run: go test -v ./... slinkwatch-1.1/Gopkg.lock000066400000000000000000000173221354745356700154730ustar00rootroot00000000000000# This file is autogenerated, do not edit; changes may be undone by the next 'dep ensure'. [[projects]] digest = "1:e92f5581902c345eb4ceffdcd4a854fb8f73cf436d47d837d1ec98ef1fe0a214" name = "github.com/StackExchange/wmi" packages = ["."] pruneopts = "UT" revision = "5d049714c4a64225c3c79a7cf7d02f7fb5b96338" version = "1.0.0" [[projects]] digest = "1:b3859c256fbb284fec5882f599e7e51cba5a3a9dd70e5d8d2bcdb218c4c5ac0d" name = "github.com/coreos/go-systemd" packages = [ "dbus", "util" ] pruneopts = "UT" revision = "39ca1b05acc7ad1220e09f133283b8859a8b71ab" version = "v17" [[projects]] digest = "1:6e2ff82d2fe11ee35ec8dceb4346b8144a761f1c8655592c4ebe99a92fcec327" name = "github.com/coreos/pkg" packages = ["dlopen"] pruneopts = "UT" revision = "97fdf19511ea361ae1c100dd393cc47f8dcfa1e1" version = "v4" [[projects]] digest = "1:7cb4fdca4c251b3ef8027c90ea35f70c7b661a593b9eeae34753c65499098bb1" name = "github.com/cpuguy83/go-md2man" packages = ["md2man"] pruneopts = "UT" revision = "20f5889cbdc3c73dbd2862796665e7c465ade7d1" version = "v1.0.8" [[projects]] digest = "1:abeb38ade3f32a92943e5be54f55ed6d6e3b6602761d74b4aab4c9dd45c18abd" name = "github.com/fsnotify/fsnotify" packages = ["."] pruneopts = "UT" revision = "c2828203cd70a50dcccfb2761f8b1f8ceef9a8e9" version = "v1.4.7" [[projects]] digest = "1:64a5a67c69b70c2420e607a8545d674a23778ed9c3e80607bfd17b77c6c87f6a" name = "github.com/go-ole/go-ole" packages = [ ".", "oleutil" ] pruneopts = "UT" revision = "a41e3c4b706f6ae8dfbff342b06e40fa4d2d0506" version = "v1.2.1" [[projects]] digest = "1:57fa4c058c21ce25d0b7272518dd746065117abf6cc706158b0d361202024520" name = "github.com/godbus/dbus" packages = ["."] pruneopts = "UT" revision = "a389bdde4dd695d414e47b755e95e72b7826432c" version = "v4.1.0" [[projects]] digest = "1:c0d19ab64b32ce9fe5cf4ddceba78d5bc9807f0016db6b1183599da3dcc24d10" name = "github.com/hashicorp/hcl" packages = [ ".", "hcl/ast", "hcl/parser", "hcl/printer", "hcl/scanner", "hcl/strconv", "hcl/token", "json/parser", "json/scanner", "json/token" ] pruneopts = "UT" revision = "8cb6e5b959231cc1119e43259c4a608f9c51a241" version = "v1.0.0" [[projects]] digest = "1:870d441fe217b8e689d7949fef6e43efbc787e50f200cb1e70dbca9204a1d6be" name = "github.com/inconshreveable/mousetrap" packages = ["."] pruneopts = "UT" revision = "76626ae9c91c4f2a10f34cad8ce83ea42c93bb75" version = "v1.0" [[projects]] digest = "1:0a69a1c0db3591fcefb47f115b224592c8dfa4368b7ba9fae509d5e16cdc95c8" name = "github.com/konsorten/go-windows-terminal-sequences" packages = ["."] pruneopts = "UT" revision = "5c8c8bd35d3832f5d134ae1e1e375b69a4d25242" version = "v1.0.1" [[projects]] digest = "1:c568d7727aa262c32bdf8a3f7db83614f7af0ed661474b24588de635c20024c7" name = "github.com/magiconair/properties" packages = ["."] pruneopts = "UT" revision = "c2353362d570a7bfa228149c62842019201cfb71" version = "v1.8.0" [[projects]] digest = "1:53bc4cd4914cd7cd52139990d5170d6dc99067ae31c56530621b18b35fc30318" name = "github.com/mitchellh/mapstructure" packages = ["."] pruneopts = "UT" revision = "3536a929edddb9a5b34bd6861dc4a9647cb459fe" version = "v1.1.2" [[projects]] digest = "1:95741de3af260a92cc5c7f3f3061e85273f5a81b5db20d4bd68da74bd521675e" name = "github.com/pelletier/go-toml" packages = ["."] pruneopts = "UT" revision = "c01d1270ff3e442a8a57cddc1c92dc1138598194" version = "v1.2.0" [[projects]] digest = "1:b36a0ede02c4c2aef7df7f91cbbb7bb88a98b5d253509d4f997dda526e50c88c" name = "github.com/russross/blackfriday" packages = ["."] pruneopts = "UT" revision = "05f3235734ad95d0016f6a23902f06461fcf567a" version = "v1.5.2" [[projects]] digest = "1:70537147f6ac44be08251f350024f3071969d39d4900d87d884d01f1c765f091" name = "github.com/ryanuber/columnize" packages = ["."] pruneopts = "UT" revision = "983d3a5fab1bf04d1b412465d2d9f8430e2e917e" version = "v2.1.0" [[projects]] branch = "master" digest = "1:e804ede5a3ed5131e1d4b85873f3cfe32e05bcbe720af135c5c363e567696b07" name = "github.com/satta/ifplugo" packages = ["."] pruneopts = "UT" revision = "8b80699998aadf3f5896b6955cc78ad7b8bcdf91" [[projects]] digest = "1:77c9c5643e2b8f7bd2f8c99e78ed34179c6a7b7b8caaf1e405186eaa763eeb09" name = "github.com/shirou/gopsutil" packages = [ "internal/common", "net" ] pruneopts = "UT" revision = "8048a2e9c5773235122027dd585cf821b2af1249" version = "v2.18.07" [[projects]] digest = "1:3f53e9e4dfbb664cd62940c9c4b65a2171c66acd0b7621a1a6b8e78513525a52" name = "github.com/sirupsen/logrus" packages = ["."] pruneopts = "UT" revision = "ad15b42461921f1fb3529b058c6786c6a45d5162" version = "v1.1.1" [[projects]] digest = "1:6a4a11ba764a56d2758899ec6f3848d24698d48442ebce85ee7a3f63284526cd" name = "github.com/spf13/afero" packages = [ ".", "mem" ] pruneopts = "UT" revision = "d40851caa0d747393da1ffb28f7f9d8b4eeffebd" version = "v1.1.2" [[projects]] digest = "1:08d65904057412fc0270fc4812a1c90c594186819243160dc779a402d4b6d0bc" name = "github.com/spf13/cast" packages = ["."] pruneopts = "UT" revision = "8c9545af88b134710ab1cd196795e7f2388358d7" version = "v1.3.0" [[projects]] digest = "1:e01b05ba901239c783dfe56450bcde607fc858908529868259c9a8765dc176d0" name = "github.com/spf13/cobra" packages = [ ".", "doc" ] pruneopts = "UT" revision = "ef82de70bb3f60c65fb8eebacbb2d122ef517385" version = "v0.0.3" [[projects]] digest = "1:68ea4e23713989dc20b1bded5d9da2c5f9be14ff9885beef481848edd18c26cb" name = "github.com/spf13/jwalterweatherman" packages = ["."] pruneopts = "UT" revision = "4a4406e478ca629068e7768fc33f3f044173c0a6" version = "v1.0.0" [[projects]] digest = "1:c1b1102241e7f645bc8e0c22ae352e8f0dc6484b6cb4d132fa9f24174e0119e2" name = "github.com/spf13/pflag" packages = ["."] pruneopts = "UT" revision = "298182f68c66c05229eb03ac171abe6e309ee79a" version = "v1.0.3" [[projects]] digest = "1:214775c11fd26da94a100111a62daa25339198a4f9c57cb4aab352da889f5b93" name = "github.com/spf13/viper" packages = ["."] pruneopts = "UT" revision = "2c12c60302a5a0e62ee102ca9bc996277c2f64f5" version = "v1.2.1" [[projects]] branch = "master" digest = "1:3f3a05ae0b95893d90b9b3b5afdb79a9b3d96e4e36e099d841ae602e4aca0da8" name = "golang.org/x/crypto" packages = ["ssh/terminal"] pruneopts = "UT" revision = "dab2b1051b5dd33a57e97c4774ed152e6a6c9a13" [[projects]] branch = "master" digest = "1:d2605ed96ca0244a457fa8e6c37d5c370ce98ea09dcc21e5e07d967bfcb78878" name = "golang.org/x/sys" packages = [ "unix", "windows" ] pruneopts = "UT" revision = "95b1ffbd15a57cc5abb3f04402b9e8ec0016a52c" [[projects]] digest = "1:8029e9743749d4be5bc9f7d42ea1659471767860f0cdc34d37c3111bd308a295" name = "golang.org/x/text" packages = [ "internal/gen", "internal/triegen", "internal/ucd", "transform", "unicode/cldr", "unicode/norm" ] pruneopts = "UT" revision = "f21a4dfb5e38f5895301dc265a8def02365cc3d0" version = "v0.3.0" [[projects]] digest = "1:342378ac4dcb378a5448dd723f0784ae519383532f5e70ade24132c4c8693202" name = "gopkg.in/yaml.v2" packages = ["."] pruneopts = "UT" revision = "5420a8b6744d3b0345ab293f6fcba19c978f1183" version = "v2.2.1" [solve-meta] analyzer-name = "dep" analyzer-version = 1 input-imports = [ "github.com/coreos/go-systemd/dbus", "github.com/coreos/go-systemd/util", "github.com/ryanuber/columnize", "github.com/satta/ifplugo", "github.com/sirupsen/logrus", "github.com/spf13/cobra", "github.com/spf13/cobra/doc", "github.com/spf13/viper", "gopkg.in/yaml.v2" ] solver-name = "gps-cdcl" solver-version = 1 slinkwatch-1.1/Gopkg.toml000066400000000000000000000010531354745356700155100ustar00rootroot00000000000000[[constraint]] name = "github.com/coreos/go-systemd" version = "17.0.0" [[constraint]] name = "github.com/ryanuber/columnize" version = "2.1.0" [[constraint]] branch = "master" name = "github.com/satta/ifplugo" [[constraint]] name = "github.com/sirupsen/logrus" version = "1.1.1" [[constraint]] name = "github.com/spf13/cobra" version = "0.0.3" [[constraint]] name = "github.com/spf13/viper" version = "1.2.1" [[constraint]] name = "gopkg.in/yaml.v2" version = "2.2.1" [prune] go-tests = true unused-packages = true slinkwatch-1.1/LICENSE000066400000000000000000000431101354745356700145510ustar00rootroot00000000000000 GNU GENERAL PUBLIC LICENSE Version 2, June 1991 Copyright (C) 1989, 1991 Free Software Foundation, Inc. 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA Everyone is permitted to copy and distribute verbatim copies of this license document, but changing it is not allowed. Preamble The licenses for most software are designed to take away your freedom to share and change it. By contrast, the GNU General Public License is intended to guarantee your freedom to share and change free software--to make sure the software is free for all its users. This General Public License applies to most of the Free Software Foundation's software and to any other program whose authors commit to using it. (Some other Free Software Foundation software is covered by the GNU Library General Public License instead.) You can apply it to your programs, too. When we speak of free software, we are referring to freedom, not price. Our General Public Licenses are designed to make sure that you have the freedom to distribute copies of free software (and charge for this service if you wish), that you receive source code or can get it if you want it, that you can change the software or use pieces of it in new free programs; and that you know you can do these things. To protect your rights, we need to make restrictions that forbid anyone to deny you these rights or to ask you to surrender the rights. These restrictions translate to certain responsibilities for you if you distribute copies of the software, or if you modify it. For example, if you distribute copies of such a program, whether gratis or for a fee, you must give the recipients all the rights that you have. You must make sure that they, too, receive or can get the source code. And you must show them these terms so they know their rights. We protect your rights with two steps: (1) copyright the software, and (2) offer you this license which gives you legal permission to copy, distribute and/or modify the software. Also, for each author's protection and ours, we want to make certain that everyone understands that there is no warranty for this free software. If the software is modified by someone else and passed on, we want its recipients to know that what they have is not the original, so that any problems introduced by others will not reflect on the original authors' reputations. Finally, any free program is threatened constantly by software patents. We wish to avoid the danger that redistributors of a free program will individually obtain patent licenses, in effect making the program proprietary. To prevent this, we have made it clear that any patent must be licensed for everyone's free use or not licensed at all. The precise terms and conditions for copying, distribution and modification follow. GNU GENERAL PUBLIC LICENSE TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION 0. This License applies to any program or other work which contains a notice placed by the copyright holder saying it may be distributed under the terms of this General Public License. The "Program", below, refers to any such program or work, and a "work based on the Program" means either the Program or any derivative work under copyright law: that is to say, a work containing the Program or a portion of it, either verbatim or with modifications and/or translated into another language. (Hereinafter, translation is included without limitation in the term "modification".) Each licensee is addressed as "you". Activities other than copying, distribution and modification are not covered by this License; they are outside its scope. The act of running the Program is not restricted, and the output from the Program is covered only if its contents constitute a work based on the Program (independent of having been made by running the Program). Whether that is true depends on what the Program does. 1. You may copy and distribute verbatim copies of the Program's source code as you receive it, in any medium, provided that you conspicuously and appropriately publish on each copy an appropriate copyright notice and disclaimer of warranty; keep intact all the notices that refer to this License and to the absence of any warranty; and give any other recipients of the Program a copy of this License along with the Program. You may charge a fee for the physical act of transferring a copy, and you may at your option offer warranty protection in exchange for a fee. 2. You may modify your copy or copies of the Program or any portion of it, thus forming a work based on the Program, and copy and distribute such modifications or work under the terms of Section 1 above, provided that you also meet all of these conditions: a) You must cause the modified files to carry prominent notices stating that you changed the files and the date of any change. b) You must cause any work that you distribute or publish, that in whole or in part contains or is derived from the Program or any part thereof, to be licensed as a whole at no charge to all third parties under the terms of this License. c) If the modified program normally reads commands interactively when run, you must cause it, when started running for such interactive use in the most ordinary way, to print or display an announcement including an appropriate copyright notice and a notice that there is no warranty (or else, saying that you provide a warranty) and that users may redistribute the program under these conditions, and telling the user how to view a copy of this License. (Exception: if the Program itself is interactive but does not normally print such an announcement, your work based on the Program is not required to print an announcement.) These requirements apply to the modified work as a whole. If identifiable sections of that work are not derived from the Program, and can be reasonably considered independent and separate works in themselves, then this License, and its terms, do not apply to those sections when you distribute them as separate works. But when you distribute the same sections as part of a whole which is a work based on the Program, the distribution of the whole must be on the terms of this License, whose permissions for other licensees extend to the entire whole, and thus to each and every part regardless of who wrote it. Thus, it is not the intent of this section to claim rights or contest your rights to work written entirely by you; rather, the intent is to exercise the right to control the distribution of derivative or collective works based on the Program. In addition, mere aggregation of another work not based on the Program with the Program (or with a work based on the Program) on a volume of a storage or distribution medium does not bring the other work under the scope of this License. 3. You may copy and distribute the Program (or a work based on it, under Section 2) in object code or executable form under the terms of Sections 1 and 2 above provided that you also do one of the following: a) Accompany it with the complete corresponding machine-readable source code, which must be distributed under the terms of Sections 1 and 2 above on a medium customarily used for software interchange; or, b) Accompany it with a written offer, valid for at least three years, to give any third party, for a charge no more than your cost of physically performing source distribution, a complete machine-readable copy of the corresponding source code, to be distributed under the terms of Sections 1 and 2 above on a medium customarily used for software interchange; or, c) Accompany it with the information you received as to the offer to distribute corresponding source code. (This alternative is allowed only for noncommercial distribution and only if you received the program in object code or executable form with such an offer, in accord with Subsection b above.) The source code for a work means the preferred form of the work for making modifications to it. For an executable work, complete source code means all the source code for all modules it contains, plus any associated interface definition files, plus the scripts used to control compilation and installation of the executable. However, as a special exception, the source code distributed need not include anything that is normally distributed (in either source or binary form) with the major components (compiler, kernel, and so on) of the operating system on which the executable runs, unless that component itself accompanies the executable. If distribution of executable or object code is made by offering access to copy from a designated place, then offering equivalent access to copy the source code from the same place counts as distribution of the source code, even though third parties are not compelled to copy the source along with the object code. 4. You may not copy, modify, sublicense, or distribute the Program except as expressly provided under this License. Any attempt otherwise to copy, modify, sublicense or distribute the Program is void, and will automatically terminate your rights under this License. However, parties who have received copies, or rights, from you under this License will not have their licenses terminated so long as such parties remain in full compliance. 5. You are not required to accept this License, since you have not signed it. However, nothing else grants you permission to modify or distribute the Program or its derivative works. These actions are prohibited by law if you do not accept this License. Therefore, by modifying or distributing the Program (or any work based on the Program), you indicate your acceptance of this License to do so, and all its terms and conditions for copying, distributing or modifying the Program or works based on it. 6. Each time you redistribute the Program (or any work based on the Program), the recipient automatically receives a license from the original licensor to copy, distribute or modify the Program subject to these terms and conditions. You may not impose any further restrictions on the recipients' exercise of the rights granted herein. You are not responsible for enforcing compliance by third parties to this License. 7. If, as a consequence of a court judgment or allegation of patent infringement or for any other reason (not limited to patent issues), conditions are imposed on you (whether by court order, agreement or otherwise) that contradict the conditions of this License, they do not excuse you from the conditions of this License. If you cannot distribute so as to satisfy simultaneously your obligations under this License and any other pertinent obligations, then as a consequence you may not distribute the Program at all. For example, if a patent license would not permit royalty-free redistribution of the Program by all those who receive copies directly or indirectly through you, then the only way you could satisfy both it and this License would be to refrain entirely from distribution of the Program. If any portion of this section is held invalid or unenforceable under any particular circumstance, the balance of the section is intended to apply and the section as a whole is intended to apply in other circumstances. It is not the purpose of this section to induce you to infringe any patents or other property right claims or to contest validity of any such claims; this section has the sole purpose of protecting the integrity of the free software distribution system, which is implemented by public license practices. Many people have made generous contributions to the wide range of software distributed through that system in reliance on consistent application of that system; it is up to the author/donor to decide if he or she is willing to distribute software through any other system and a licensee cannot impose that choice. This section is intended to make thoroughly clear what is believed to be a consequence of the rest of this License. 8. If the distribution and/or use of the Program is restricted in certain countries either by patents or by copyrighted interfaces, the original copyright holder who places the Program under this License may add an explicit geographical distribution limitation excluding those countries, so that distribution is permitted only in or among countries not thus excluded. In such case, this License incorporates the limitation as if written in the body of this License. 9. The Free Software Foundation may publish revised and/or new versions of the General Public License from time to time. Such new versions will be similar in spirit to the present version, but may differ in detail to address new problems or concerns. Each version is given a distinguishing version number. If the Program specifies a version number of this License which applies to it and "any later version", you have the option of following the terms and conditions either of that version or of any later version published by the Free Software Foundation. If the Program does not specify a version number of this License, you may choose any version ever published by the Free Software Foundation. 10. If you wish to incorporate parts of the Program into other free programs whose distribution conditions are different, write to the author to ask for permission. For software which is copyrighted by the Free Software Foundation, write to the Free Software Foundation; we sometimes make exceptions for this. Our decision will be guided by the two goals of preserving the free status of all derivatives of our free software and of promoting the sharing and reuse of software generally. NO WARRANTY 11. BECAUSE THE PROGRAM IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING, REPAIR OR CORRECTION. 12. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR REDISTRIBUTE THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. END OF TERMS AND CONDITIONS How to Apply These Terms to Your New Programs If you develop a new program, and you want it to be of the greatest possible use to the public, the best way to achieve this is to make it free software which everyone can redistribute and change under these terms. To do so, attach the following notices to the program. It is safest to attach them to the start of each source file to most effectively convey the exclusion of warranty; and each file should have at least the "copyright" line and a pointer to where the full notice is found. Copyright (C) This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA Also add information on how to contact you by electronic and paper mail. If the program is interactive, make it output a short notice like this when it starts in an interactive mode: Gnomovision version 69, Copyright (C) year name of author Gnomovision comes with ABSOLUTELY NO WARRANTY; for details type `show w'. This is free software, and you are welcome to redistribute it under certain conditions; type `show c' for details. The hypothetical commands `show w' and `show c' should show the appropriate parts of the General Public License. Of course, the commands you use may be called something other than `show w' and `show c'; they could even be mouse-clicks or menu items--whatever suits your program. You should also get your employer (if you work as a programmer) or your school, if any, to sign a "copyright disclaimer" for the program, if necessary. Here is a sample; alter the names: Yoyodyne, Inc., hereby disclaims all copyright interest in the program `Gnomovision' (which makes passes at compilers) written by James Hacker. , 1 April 1989 Ty Coon, President of Vice This General Public License does not permit incorporating your program into proprietary programs. If your program is a subroutine library, you may consider it more useful to permit linking proprietary applications with the library. If this is what you want to do, use the GNU Library General Public License instead of this License. slinkwatch-1.1/README.md000066400000000000000000000143271354745356700150330ustar00rootroot00000000000000# 🔃 slinkwatch [![CircleCI](https://circleci.com/gh/DCSO/slinkwatch.svg?style=svg)](https://circleci.com/gh/DCSO/slinkwatch) slinkwatch is the *Suricata Link Watcher*, a tool to dynamically maintain `interface` entries in Suricata's configuration file, depending on what network interfaces are connected. It is meant to ease deployment of identical sensor installations at many heterogenous sites, allowing to make full use of the sensor resources in the light of varying monitoring volume. ## Interaction with Suricata In order to propagate changed interface configuration to Suricata, one would need to configure Suricata in such a way that the section of the configuration YAML created by the slinkwatch template is included from a separate file, e.g. via ```yaml ... include: interfaces.yaml ... ``` in, for example, `/etc/suricata/suricata.yaml` and then specifying `/etc/suricata/interfaces.yaml` as the `--target-file` in the slinkwatch call. Note that it must be writable by the slinkwatch process! After modifying this file whenever a status change occurs, slinkwatch will attempt to restart Suricata. For systems that run [systemd](https://www.freedesktop.org/wiki/Software/systemd/), slinkwatch will always try to restart the service given by the `--service-name` option (default is `suricata.service`). On non-systemd systems, it will run a simple command to restart Suricata (default is `/etc/init.d/suricata restart`). Whether systemd is available will be checked at runtime. ## Resource assignment Support for interfaces going online and offline at runtime obviously raises the question of how to assign computing resources (i.e. detection threads) to the individual interfaces. Unless all interfaces on a sensor are completely identical in terms of supported bandwidth and traffic, it is not sufficient to simply assign equal amounts of threads to all interfaces that are connected at a given point in time. For example, one might have a 10Gbit interface `eth1` and a 1Gbit interface `eth2` on such a machine, and most certainly one would want more threads assigned to the former than to the latter. Even more importantly, how would an existing assignment be changed to be most efficient when another 10Gbit interface, say `eth3` gets a link? We address this issue using _thread weights_. That is, each interface _i_ is assigned a integer value _wi_ to denote its resource allocation importance. For example, in the case above we could assign _weth1_ = _weth3_ = 10 and _weth2_ = 2. We also consider the _active set_ of interfaces _A_ as the set of all interfaces that have an active link. On a machine with _n_ threads available for detection, we can then assign to each interface _i_ the value ![t_i=\lceil n \frac{w_i}{\sum_{j \in A}w_j} \rceil](https://latex.codecogs.com/png.latex?t_i%3D%5Clceil%20n%20%5Cfrac%7Bw_i%7D%7B%5Csum_%7Bj%20%5Cin%20A%7Dw_j%7D%20%5Crceil) as the number of threads allocated to detection for traffic on interface _i_. For example, for _n_ = 40 we would then set ![t_{\textup{eth1}} = t_{\textup{eth3}} = \lceil 40 \frac{10}{22} \rceil = 19](https://latex.codecogs.com/png.latex?t_%7B%5Ctextup%7Beth1%7D%7D%20%3D%20t_%7B%5Ctextup%7Beth3%7D%7D%20%3D%20%5Clceil%2040%20%5Cfrac%7B10%7D%7B22%7D%20%5Crceil%20%3D%2019) and ![t_{\textup{eth2}} = \lceil 40 \frac{2}{22} \rceil = 4](https://latex.codecogs.com/png.latex?t_%7B%5Ctextup%7Beth2%7D%7D%20%3D%20%5Clceil%2040%20%5Cfrac%7B2%7D%7B22%7D%20%5Crceil%20%3D%204) We aim for slight overcommitment of CPU hyperthreads to avoid idling CPUs as much as possible. ## Installing dependencies via `dep` The component of slinkwatch talking to systemd requires a specific godbus version. Please make sure to run ``` $ dep ensure ``` before building to make sure the correct version constraints apply. ## Usage Define the interfaces that are available to assign in a YAML file, together with their weights: ```yaml # Interfaces available for Suricata --- ifaces: eth1: clusterid: 98 threadweight: 10 eth2: clusterid: 97 threadweight: 2 eth3: clusterid: 96 threadweight: 10 ``` Adjust the template to fit the desired configuration format: ``` %YAML 1.1 --- af-packet:{{ range $iface, $vals := . }} - interface: {{ $iface }} threads: {{ $vals.Threads }} cluster-id: {{ $vals.ClusterID }} cluster-type: cluster_flow defrag: yes rollover: yes use-mmap: yes tpacket-v3: yes use-emergency-flush: yes buffer-size: 128000 {{ else }} - interface: default threads: auto use-mmap: yes rollover: yes tpacket-v3: yes {{ end }} ``` Finally, run slinkwatch, preferably in the background (there's also a systemd service unit file in the repo). ``` $ slinkwatch run ``` It is possible to specify the locations of the template and config file using the command line parameters: ``` $ slinkwatch run --help Run the slinkwatch service Usage: slinkwatch run [flags] Flags: -c, --config string Configuration file (default "config.yaml") -d, --delta-bytes uint threshold of bytes to be exceeded on interface to be marked as up (default 100) -h, --help help for run -i, --interfaces string Template file for interfaces (default "interfaces.tmpl") -p, --poll-interval duration poll time for interface changes (default 5s) -r, --restart-command string Suricata restart command (default "/etc/init.d/suricata restart") -s, --service-name string systemd service name for Suricata service (default "suricata.service") -t, --target-file string Target YAML file with interface information (default "/etc/suricata/interfaces.yaml") ``` ## Other commands - `slinkwatch make-config` creates an initial YAML file with skeleton config entries for local interfaces (or a subset defined by a regular expression) - `slinkwatch makeman` creates a set of man pages for the tool - `slinkwatch show-active` lists the currently active set of interfaces (useful for debugging) ## Dependencies/requirements Needs [ifplugo](http://github.com/satta/ifplugo) for network change notifications. This introduces a runtime dependency on libdaemon. It is also highly recommended to use systemd. ## Authors Sascha Steinbiss ## License GPL2 (due to ifplugo being GPL2). slinkwatch-1.1/activeset.go000066400000000000000000000057561354745356700161000ustar00rootroot00000000000000package slinkwatch // This file is part of slinkwatch. // // slinkwatch is free software; you can redistribute it and/or modify it // under the terms of the GNU General Public License as published by // the Free Software Foundation; either version 2 of the License, or // (at your option) any later version. // // slinkwatch is distributed in the hope that it will be useful, but // WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU // General Public License for more details. // // You should have received a copy of the GNU General Public License // along with slinkwatch; if not, write to the Free Software Foundation, // Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA. import ( "bytes" "math" "runtime" "text/template" yaml "gopkg.in/yaml.v2" ) // InterfaceInfo contains basic information about a specific interface entry. type InterfaceInfo struct { Threads int ClusterID int ExtraOptions map[string]string } // ActiveSet contains descriptions of the currently connected interfaces. type ActiveSet struct { Config *Config Ifaces map[string]InterfaceInfo } // MakeActiveSet returns a new empty ActiveSet. func MakeActiveSet(config *Config) *ActiveSet { return &ActiveSet{ Config: config, Ifaces: make(map[string]InterfaceInfo), } } // Reset clears the interfaces associated with an ActiveSet. func (a *ActiveSet) Reset() { a.Ifaces = make(map[string]InterfaceInfo) } // String returns a string representation of an ActiveSet, listing its // interfaces. func (a *ActiveSet) String() string { out := "" i := 0 if len(a.Ifaces) == 0 { return "" } for k := range a.Ifaces { out += k if i != len(a.Ifaces)-1 { out += "/" i++ } } return out } // Add adds an interface to a given ActiveSet. func (a *ActiveSet) Add(iface string) { if _, ok := a.Config.Ifaces[iface]; ok { a.Ifaces[iface] = InterfaceInfo{} } // from here we can assume that we only handle the intersection of the // configured interfaces and the observed interfaces } // Len returns the number of interfaces in the active set. func (a *ActiveSet) Len() int { return len(a.Ifaces) } // ToYAML returns the YAML representation of an ActiveSet, given a template and // a configuration with thread weights. func (a *ActiveSet) ToYAML(tmpl *template.Template, config *Config) (string, error) { threads := runtime.NumCPU() totalweight := 0 for intf := range a.Ifaces { totalweight += config.Ifaces[intf].ThreadWeight } for intf := range a.Ifaces { a.Ifaces[intf] = InterfaceInfo{ Threads: int(math.Ceil(float64(threads) * (float64(config.Ifaces[intf].ThreadWeight) / float64(totalweight)))), ClusterID: config.Ifaces[intf].ClusterID, ExtraOptions: config.Ifaces[intf].ExtraOptions, } } buf := new(bytes.Buffer) err := tmpl.Execute(buf, a.Ifaces) if err != nil { return "", err } var t interface{} err = yaml.Unmarshal(buf.Bytes(), &t) if err != nil { return "", err } return buf.String(), nil } slinkwatch-1.1/activeset_test.go000066400000000000000000000076571354745356700171410ustar00rootroot00000000000000package slinkwatch import ( "io/ioutil" "os" "testing" "text/template" ) // This file is part of slinkwatch. // // slinkwatch is free software; you can redistribute it and/or modify it // under the terms of the GNU General Public License as published by // the Free Software Foundation; either version 2 of the License, or // (at your option) any later version. // // slinkwatch is distributed in the hope that it will be useful, but // WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU // General Public License for more details. // // You should have received a copy of the GNU General Public License // along with slinkwatch; if not, write to the Free Software Foundation, // Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA. func mkConfig() *Config { return &Config{ Ifaces: map[string]ConfIface{ "eth0": ConfIface{ ThreadWeight: 2, ClusterID: 99, }, "eth1": ConfIface{ ThreadWeight: 2, ClusterID: 99, ExtraOptions: map[string]string{ "foo": "bar", }, }, }, } } func mkConfigFile(t *testing.T) *os.File { cfgString := `# Interfaces available for Suricata --- ifaces: eth0: threadweight: 2 clusterid: 99 extraopts: cluster-type: cluster_qm foo: barbaz hasi: 234 eth1: threadweight: 2 clusterid: 99 extraopts: cluster-type: cluster_flow captain: jack` tempFile, err := ioutil.TempFile("", "slinkwatch") if err != nil { t.Fatal(err) } tempFile.WriteString(cfgString) return tempFile } func mkEmptyConfig() *Config { return &Config{} } func mkTemplate(t *testing.T) *template.Template { tmpl := `%YAML 1.1 --- af-packet:{{ range $iface, $vals := . }} - interface: {{ $iface }} threads: {{ $vals.Threads }} cluster-id: {{ $vals.ClusterID }}{{ range $extrakey, $extraval := $vals.ExtraOptions }} {{ $extrakey }}: {{ $extraval}}{{ end }} {{ else }} - interface: default threads: auto {{ end }}` tmplCompiled, err := template.New("test").Parse(tmpl) if err != nil { t.Fatal(err) } return tmplCompiled } func TestActiveSetEmptyIfaces(t *testing.T) { cfg := mkConfig() as := MakeActiveSet(cfg) if as.Len() != 0 { t.Fail() } if as.String() != "" { t.Fail() } } func TestActiveSetNoMatchConfig(t *testing.T) { cfg := mkConfig() as := MakeActiveSet(cfg) as.Add("eth4") if as.Len() != 0 { t.Fail() } } func TestActiveSetOneIface(t *testing.T) { cfg := mkConfig() as := MakeActiveSet(cfg) as.Add("eth0") if as.Len() != 1 { t.Fail() } } func TestActiveSetOneIfaceTwice(t *testing.T) { cfg := mkConfig() as := MakeActiveSet(cfg) as.Add("eth0") as.Add("eth0") if as.Len() != 1 { t.Fail() } } func TestActiveSetTwoIfaces(t *testing.T) { cfg := mkConfig() as := MakeActiveSet(cfg) as.Add("eth0") as.Add("eth1") if as.Len() != 2 { t.Fail() } as.Reset() if as.Len() != 0 { t.Fail() } } func TestActiveSetTwoIfacesToString(t *testing.T) { cfg := mkConfig() as := MakeActiveSet(cfg) as.Add("eth0") as.Add("eth1") if as.String() == "" { t.Fail() } as.Reset() if as.String() != "" { t.Fail() } } func TestActiveSetToYAML(t *testing.T) { cfg := mkConfig() as := MakeActiveSet(cfg) as.Add("eth0") as.Add("eth1") y, err := as.ToYAML(mkTemplate(t), cfg) if err != nil { t.Fatal(err) } if len(y) == 0 { t.Fatal(err) } } func TestActiveSetEmptyToYAML(t *testing.T) { cfg := mkConfig() as := MakeActiveSet(cfg) y, err := as.ToYAML(mkTemplate(t), cfg) if err != nil { t.Fatal(err) } if len(y) == 0 { t.Fatal(err) } } func TestActiveSetConfigFileToYAML(t *testing.T) { cfg := &Config{} as := MakeActiveSet(cfg) tf := mkConfigFile(t) defer os.Remove(tf.Name()) err := cfg.LoadConfig(tf.Name()) if err != nil { t.Fatal(err) } as.Add("eth0") as.Add("eth1") y, err := as.ToYAML(mkTemplate(t), cfg) if err != nil { t.Fatal(err) } if len(y) == 0 { t.Fatal(err) } } slinkwatch-1.1/cmd/000077500000000000000000000000001354745356700143105ustar00rootroot00000000000000slinkwatch-1.1/cmd/slinkwatch/000077500000000000000000000000001354745356700164575ustar00rootroot00000000000000slinkwatch-1.1/cmd/slinkwatch/cmds/000077500000000000000000000000001354745356700174055ustar00rootroot00000000000000slinkwatch-1.1/cmd/slinkwatch/cmds/make-config.go000066400000000000000000000040771354745356700221240ustar00rootroot00000000000000package cmds // This file is part of slinkwatch. // // slinkwatch is free software; you can redistribute it and/or modify it // under the terms of the GNU General Public License as published by // the Free Software Foundation; either version 2 of the License, or // (at your option) any later version. // // slinkwatch is distributed in the hope that it will be useful, but // WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU // General Public License for more details. // // You should have received a copy of the GNU General Public License // along with slinkwatch; if not, write to the Free Software Foundation, // Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA. import ( "fmt" "net" "regexp" "github.com/DCSO/slinkwatch" log "github.com/sirupsen/logrus" "github.com/spf13/cobra" "gopkg.in/yaml.v2" ) // confCmd represents the make-config command var confCmd = &cobra.Command{ Use: "make-config [options]", Short: "Create initial configuration file from local interfaces", Run: func(cmd *cobra.Command, args []string) { pattern, err := cmd.Flags().GetString("pattern") if err != nil { log.Fatal(err) } pat, err := regexp.CompilePOSIX(pattern) if err != nil { log.Fatal(err) } netIfs, err := net.Interfaces() consideredIfs := make([]string, 0) if err != nil { log.Fatal(err) } for _, i := range netIfs { if pat.Match([]byte(i.Name)) { consideredIfs = append(consideredIfs, i.Name) } } cfg := slinkwatch.Config{ Ifaces: make(map[string]slinkwatch.ConfIface), } cid := 99 for _, i := range consideredIfs { cif := slinkwatch.ConfIface{ ThreadWeight: 1, ClusterID: cid, } cid-- cfg.Ifaces[i] = cif } out, err := yaml.Marshal(cfg) if err != nil { log.Fatal(err) } fmt.Println("# Interfaces available for Suricata") fmt.Println("---") fmt.Println(string(out[:])) }, } func init() { rootCmd.AddCommand(confCmd) confCmd.Flags().StringP("pattern", "p", ".*", "Selection pattern for interfaces to include") } slinkwatch-1.1/cmd/slinkwatch/cmds/makeman.go000066400000000000000000000027501354745356700213510ustar00rootroot00000000000000package cmds // This file is part of slinkwatch. // // slinkwatch is free software; you can redistribute it and/or modify it // under the terms of the GNU General Public License as published by // the Free Software Foundation; either version 2 of the License, or // (at your option) any later version. // // slinkwatch is distributed in the hope that it will be useful, but // WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU // General Public License for more details. // // You should have received a copy of the GNU General Public License // along with slinkwatch; if not, write to the Free Software Foundation, // Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA. import ( log "github.com/sirupsen/logrus" "github.com/spf13/cobra" "github.com/spf13/cobra/doc" ) // mmanCmd represents the makeman command var mmanCmd = &cobra.Command{ Use: "makeman [options]", Short: "Create man pages", Run: func(cmd *cobra.Command, args []string) { targetDir, err := cmd.Flags().GetString("dir") if err != nil { log.Fatal(err) } header := &doc.GenManHeader{} err = doc.GenManTree(rootCmd, header, targetDir) if err != nil { log.Fatal(err) } for _, v := range rootCmd.Commands() { err = doc.GenManTree(v, header, targetDir) if err != nil { log.Fatal(err) } } }, } func init() { rootCmd.AddCommand(mmanCmd) mmanCmd.Flags().StringP("dir", "d", ".", "target directory for man pages") } slinkwatch-1.1/cmd/slinkwatch/cmds/root.go000066400000000000000000000030161354745356700207170ustar00rootroot00000000000000package cmds // This file is part of slinkwatch. // // slinkwatch is free software; you can redistribute it and/or modify it // under the terms of the GNU General Public License as published by // the Free Software Foundation; either version 2 of the License, or // (at your option) any later version. // // slinkwatch is distributed in the hope that it will be useful, but // WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU // General Public License for more details. // // You should have received a copy of the GNU General Public License // along with slinkwatch; if not, write to the Free Software Foundation, // Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA. import ( "fmt" "os" "github.com/spf13/cobra" "github.com/spf13/viper" ) var cfgFile string var rootCmd = &cobra.Command{ Use: "slinkwatch", Short: "automatic maintenance of Suricata monitoring interfaces", Long: `slinkwatch is a tool to dynamically maintain interface entries in Suricata's configuration file, depending on what network interfaces are connected. It is meant to ease deployment of identical sensor installations at many heterogenous sites, allowing to make full use of the sensor resources in the light of varying monitoring volume.`, } // Execute runs the root command. func Execute() { if err := rootCmd.Execute(); err != nil { fmt.Println(err) os.Exit(1) } } func init() { cobra.OnInitialize(initConfig) } func initConfig() { viper.AutomaticEnv() } slinkwatch-1.1/cmd/slinkwatch/cmds/run.go000066400000000000000000000115341354745356700205440ustar00rootroot00000000000000package cmds // This file is part of slinkwatch. // // slinkwatch is free software; you can redistribute it and/or modify it // under the terms of the GNU General Public License as published by // the Free Software Foundation; either version 2 of the License, or // (at your option) any later version. // // slinkwatch is distributed in the hope that it will be useful, but // WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU // General Public License for more details. // // You should have received a copy of the GNU General Public License // along with slinkwatch; if not, write to the Free Software Foundation, // Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA. import ( "io/ioutil" "os" "os/signal" "strings" "syscall" "text/template" "time" "github.com/DCSO/slinkwatch" "github.com/satta/ifplugo" log "github.com/sirupsen/logrus" "github.com/spf13/cobra" ) func runMain(cmd *cobra.Command, args []string) { ifaceFile, err := cmd.Flags().GetString("interfaces") if err != nil { log.Fatal(err) } tmpl, err := template.ParseFiles(ifaceFile) log.Infof("Parsing template file %s", ifaceFile) if err != nil { log.Fatalf("Invalid template: %s", err.Error()) } log.Infof("Parsing of %s done, success", ifaceFile) var conf slinkwatch.Config configFile, err := cmd.Flags().GetString("config") if err != nil { log.Fatal(err) } log.Infof("Loading config file %s", configFile) err = conf.LoadConfig(configFile) if err != nil { log.Fatalf("Error loading config: %s", err.Error()) } log.Infof("Config file %s loaded successfully", configFile) log.Infof("Watching interfaces %s", strings.Join(conf.GetWatchedInterfaces(), ",")) restartCmd, err := cmd.Flags().GetString("restart-command") if err != nil { log.Fatal(err) } log.Infof("Suricata restart command set to '%s'", restartCmd) serviceName, err := cmd.Flags().GetString("service-name") if err != nil { log.Fatal(err) } log.Infof("Suricata service name command set to '%s'", restartCmd) restartMan, err := slinkwatch.MakeRestartManager(restartCmd, serviceName) if err != nil { log.Fatal(err) } targetFile, err := cmd.Flags().GetString("target-file") if err != nil { log.Fatal(err) } log.Infof("Target file set to %s", targetFile) pollInterval, err := cmd.Flags().GetDuration("poll-interval") if err != nil { log.Fatal(err) } log.Infof("Poll interval set to %v", pollInterval) deltaBytes, err := cmd.Flags().GetUint("delta-bytes") if err != nil { log.Fatal(err) } log.Infof("Delta bytes set to %v", deltaBytes) activeSet := slinkwatch.MakeActiveSet(&conf) notices := make(chan ifplugo.LinkStatusSample, 10) mon := ifplugo.MakeLinkStatusMonitor(pollInterval, conf.GetWatchedInterfaces(), notices) if deltaBytes > 0 { mon.CheckIncomingDelta(true, uint64(deltaBytes)) } mon.Run() go func() { for n := range notices { changed := false activeSet.Reset() for i, v := range n.Ifaces { if v == ifplugo.InterfaceUp { activeSet.Add(i) changed = true } } out, err := activeSet.ToYAML(tmpl, &conf) if err != nil { log.Fatalf("Error rendering to YAML: %s", err.Error()) } if changed { log.Infof("interface state change detected, active set is %s", activeSet) } else { log.Infof("interface state change detected, active set is empty") } err = ioutil.WriteFile(targetFile, []byte(out), 0644) if err != nil { log.Println(err) } else { err = restartMan.RestartSuricata() if err != nil { log.Println(err) } else { log.Println("restart requested successfully") } } } }() c := make(chan os.Signal, 1) signal.Notify(c, os.Interrupt, syscall.SIGTERM, syscall.SIGINT) go func() { for sig := range c { if sig == syscall.SIGTERM || sig == syscall.SIGINT { log.Info("received SIGTERM, terminating") close(notices) os.Exit(1) } } }() select {} } // runCmd represents the run command var runCmd = &cobra.Command{ Use: "run", Short: "Run the slinkwatch service", Run: func(cmd *cobra.Command, args []string) { runMain(cmd, args) }, } func init() { rootCmd.AddCommand(runCmd) runCmd.Flags().StringP("config", "c", "config.yaml", "Configuration file") runCmd.Flags().StringP("interfaces", "i", "interfaces.tmpl", "Template file for interfaces") runCmd.Flags().StringP("target-file", "t", "/etc/suricata/interfaces.yaml", "Target YAML file with interface information") runCmd.Flags().StringP("restart-command", "r", "/etc/init.d/suricata restart", "Suricata restart command") runCmd.Flags().DurationP("poll-interval", "p", 5*time.Second, "poll time for interface changes") runCmd.Flags().StringP("service-name", "s", "suricata.service", "systemd service name for Suricata service") runCmd.Flags().UintP("delta-bytes", "d", 100, "threshold of bytes to be exceeded on interface to be marked as up") } slinkwatch-1.1/cmd/slinkwatch/cmds/show-active.go000066400000000000000000000043341354745356700221710ustar00rootroot00000000000000package cmds // This file is part of slinkwatch. // // slinkwatch is free software; you can redistribute it and/or modify it // under the terms of the GNU General Public License as published by // the Free Software Foundation; either version 2 of the License, or // (at your option) any later version. // // slinkwatch is distributed in the hope that it will be useful, but // WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU // General Public License for more details. // // You should have received a copy of the GNU General Public License // along with slinkwatch; if not, write to the Free Software Foundation, // Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA. import ( "fmt" "net" "github.com/ryanuber/columnize" "github.com/satta/ifplugo" log "github.com/sirupsen/logrus" "github.com/spf13/cobra" "github.com/DCSO/slinkwatch" ) // showactCmd represents the show-active command var showactCmd = &cobra.Command{ Use: "show-active [options]", Short: "List active set of interfaces", Run: func(cmd *cobra.Command, args []string) { showAll, err := cmd.Flags().GetBool("all") if err != nil { log.Fatal(err) } var interfaces []string if showAll { interfaces = make([]string, 0) netIfs, err := net.Interfaces() if err != nil { log.Fatal(err) } for _, i := range netIfs { interfaces = append(interfaces, i.Name) } } else { var conf slinkwatch.Config configFile, err := cmd.Flags().GetString("config") if err != nil { log.Fatal(err) } err = conf.LoadConfig(configFile) if err != nil { log.Fatalf("Error loading config: %s", err.Error()) } interfaces = conf.GetWatchedInterfaces() } output := make([]string, 0) for _, i := range interfaces { status, err := ifplugo.GetLinkStatus(i) if err != nil { continue } line := fmt.Sprintf("%s|%s\n", i, status) output = append(output, line) } result := columnize.SimpleFormat(output) fmt.Println(result) }, } func init() { rootCmd.AddCommand(showactCmd) showactCmd.Flags().BoolP("all", "a", false, "Show status for all interfaces") showactCmd.Flags().StringP("config", "c", "config.yaml", "Configuration file") } slinkwatch-1.1/cmd/slinkwatch/main.go000066400000000000000000000015231354745356700177330ustar00rootroot00000000000000package main import cmd "github.com/DCSO/slinkwatch/cmd/slinkwatch/cmds" // This file is part of slinkwatch. // // slinkwatch is free software; you can redistribute it and/or modify it // under the terms of the GNU General Public License as published by // the Free Software Foundation; either version 2 of the License, or // (at your option) any later version. // // slinkwatch is distributed in the hope that it will be useful, but // WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU // General Public License for more details. // // You should have received a copy of the GNU General Public License // along with slinkwatch; if not, write to the Free Software Foundation, // Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA. func main() { cmd.Execute() } slinkwatch-1.1/config.go000066400000000000000000000031661354745356700153470ustar00rootroot00000000000000package slinkwatch // This file is part of slinkwatch. // // slinkwatch is free software; you can redistribute it and/or modify it // under the terms of the GNU General Public License as published by // the Free Software Foundation; either version 2 of the License, or // (at your option) any later version. // // slinkwatch is distributed in the hope that it will be useful, but // WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU // General Public License for more details. // // You should have received a copy of the GNU General Public License // along with slinkwatch; if not, write to the Free Software Foundation, // Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA. import ( "io/ioutil" yaml "gopkg.in/yaml.v2" ) // ConfIface represents the configured options associated with a single // interface. type ConfIface struct { ThreadWeight int ClusterID int ExtraOptions map[string]string `yaml:"extraopts,omitempty"` } // Config represents basic configuration parsed from a file, such as interfaces // to be watched. type Config struct { Ifaces map[string]ConfIface } // LoadConfig populates a Config from a file. func (c *Config) LoadConfig(path string) error { yamlFile, err := ioutil.ReadFile(path) if err != nil { return err } err = yaml.Unmarshal(yamlFile, c) return err } // GetWatchedInterfaces returns a slice of strings, listing all interfaces // mentioned in the configuration file. func (c *Config) GetWatchedInterfaces() []string { out := make([]string, 0) for k := range c.Ifaces { out = append(out, k) } return out } slinkwatch-1.1/config.yaml000066400000000000000000000003511354745356700156750ustar00rootroot00000000000000# Interfaces available for Suricata --- ifaces: eth0: threadweight: 1 clusterid: 99 eth1: threadweight: 10 clusterid: 98 eth2: threadweight: 3 clusterid: 97 eth3: threadweight: 3 clusterid: 96 slinkwatch-1.1/config_test.go000066400000000000000000000037201354745356700164020ustar00rootroot00000000000000package slinkwatch // This file is part of slinkwatch. // // slinkwatch is free software; you can redistribute it and/or modify it // under the terms of the GNU General Public License as published by // the Free Software Foundation; either version 2 of the License, or // (at your option) any later version. // // slinkwatch is distributed in the hope that it will be useful, but // WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU // General Public License for more details. // // You should have received a copy of the GNU General Public License // along with slinkwatch; if not, write to the Free Software Foundation, // Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA. import ( "io/ioutil" "syscall" "testing" ) var watchedIfs = []string{"eth0", "eth1", "eth2", "eth3"} var testcfg = ` # Interfaces available for Suricata --- ifaces: eth0: threadweight: 1 clusterid: 99 eth1: threadweight: 10 clusterid: 98 eth2: threadweight: 3 clusterid: 97 eth3: threadweight: 3 clusterid: 96 ` func TestConfigLoad(t *testing.T) { f, err := ioutil.TempFile("", "testmainconf") if err != nil { panic(err) } defer syscall.Unlink(f.Name()) ioutil.WriteFile(f.Name(), []byte(testcfg), 0644) var cfg Config err = cfg.LoadConfig(f.Name()) if err != nil { t.Fatal(err) } seenIfs := cfg.GetWatchedInterfaces() if len(seenIfs) != len(watchedIfs) { t.Fail() } for _, v := range watchedIfs { seen := false for _, w := range seenIfs { if v == w { seen = true break } } if !seen { t.Fail() } } } func TestConfigLoadFail(t *testing.T) { testcfg := ` --- if ` f, err := ioutil.TempFile("", "testmainconf") if err != nil { panic(err) } defer syscall.Unlink(f.Name()) ioutil.WriteFile(f.Name(), []byte(testcfg), 0644) var cfg Config err = cfg.LoadConfig(f.Name()) if err == nil { t.Fatal("no error but was expected") } } slinkwatch-1.1/interfaces.tmpl000066400000000000000000000010171354745356700165650ustar00rootroot00000000000000%YAML 1.1 --- af-packet:{{ range $iface, $vals := . }} - interface: {{ $iface }} threads: {{ $vals.Threads }} cluster_type: cluster_flow defrag: yes rollover: yes use-mmap: yes tpacket-v3: yes use-emergency-flush: yes buffer-size: 128000 cluster-id: {{ $vals.ClusterID }}{{ range $extrakey, $extraval := $vals.ExtraOptions }} {{ $extrakey }}: {{ $extraval}}{{ end }} {{ else }} - interface: default threads: auto use-mmap: yes rollover: yes tpacket-v3: yes {{ end }} slinkwatch-1.1/restart.go000066400000000000000000000044511354745356700155640ustar00rootroot00000000000000package slinkwatch // This file is part of slinkwatch. // // slinkwatch is free software; you can redistribute it and/or modify it // under the terms of the GNU General Public License as published by // the Free Software Foundation; either version 2 of the License, or // (at your option) any later version. // // slinkwatch is distributed in the hope that it will be useful, but // WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU // General Public License for more details. // // You should have received a copy of the GNU General Public License // along with slinkwatch; if not, write to the Free Software Foundation, // Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA. import ( "fmt" "os/exec" "github.com/coreos/go-systemd/dbus" "github.com/coreos/go-systemd/util" log "github.com/sirupsen/logrus" ) // RestartManager encapsulates interaction with the init system to restart the // Suricata process on request. type RestartManager struct { IsSystemd bool RestartCommand string ServiceName string } // MakeRestartManager returns a new RestartManager with restart command and // service name preconfigured. func MakeRestartManager(restartCommand string, serviceName string) (*RestartManager, error) { r := &RestartManager{ IsSystemd: util.IsRunningSystemd(), RestartCommand: restartCommand, ServiceName: serviceName, } if !r.IsSystemd { log.Infoln("Not running systemd, will rely on restart command") } else { log.Infoln("systemd is available") } if !r.IsSystemd && len(restartCommand) == 0 { return nil, fmt.Errorf("Not running systemd but no restart command given") } return r, nil } // RestartSuricata triggers a Suricata restart, using the most appropriate // method. func (rm *RestartManager) RestartSuricata() error { if !rm.IsSystemd { cmd := exec.Command("sh", "-c", rm.RestartCommand) err := cmd.Run() if err != nil { return fmt.Errorf("Cannot restart Suricata: %v", err) } return nil } conn, err := dbus.New() if err != nil { return err } finishChan := make(chan string) _, err = conn.TryRestartUnit(rm.ServiceName, "replace", finishChan) if err != nil { return err } go func(ch chan string) { log.Infof("restart result: %s", <-ch) }(finishChan) return nil } slinkwatch-1.1/restart_test.go000066400000000000000000000017401354745356700166210ustar00rootroot00000000000000package slinkwatch // This file is part of slinkwatch. // // slinkwatch is free software; you can redistribute it and/or modify it // under the terms of the GNU General Public License as published by // the Free Software Foundation; either version 2 of the License, or // (at your option) any later version. // // slinkwatch is distributed in the hope that it will be useful, but // WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU // General Public License for more details. // // You should have received a copy of the GNU General Public License // along with slinkwatch; if not, write to the Free Software Foundation, // Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA. import "testing" func TestRestartManager(t *testing.T) { rm, err := MakeRestartManager("foo", "bar") if err != nil { t.Fail() } if rm.ServiceName != "bar" { t.Fail() } if rm.RestartCommand != "foo" { t.Fail() } } slinkwatch-1.1/slinkwatch.service000066400000000000000000000005371354745356700173030ustar00rootroot00000000000000[Unit] Description=Suricata dymanic interface maintenance Documentation=https://github.com/DCSO/slinkwatch Wants=network-online.target After=network-online.target [Service] SyslogIdentifier=slinkwatch EnvironmentFile=-/etc/default/slinkwatch ExecStart=/usr/bin/slinkwatch run $SLINKWATCH_ARGS Restart=on-failure [Install] WantedBy=multi-user.target