Add TM2 nagios peerpoller checking all TMs in TO

Project: http://git-wip-us.apache.org/repos/asf/incubator-trafficcontrol/repo
Commit: 
http://git-wip-us.apache.org/repos/asf/incubator-trafficcontrol/commit/2fdd9317
Tree: 
http://git-wip-us.apache.org/repos/asf/incubator-trafficcontrol/tree/2fdd9317
Diff: 
http://git-wip-us.apache.org/repos/asf/incubator-trafficcontrol/diff/2fdd9317

Branch: refs/heads/master
Commit: 2fdd9317a407fb6dfe924714630483c8b760c1a3
Parents: 5a6cf95
Author: Robert Butts <robert.o.bu...@gmail.com>
Authored: Wed Mar 15 11:15:46 2017 -0600
Committer: Dave Neuman <neu...@apache.org>
Committed: Wed Apr 12 15:43:31 2017 -0600

----------------------------------------------------------------------
 .../tools/nagios-validate-offline.go            | 19 +++++++
 .../tools/nagios-validate-peerpoller.go         | 57 +++++++++++++++-----
 2 files changed, 64 insertions(+), 12 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-trafficcontrol/blob/2fdd9317/traffic_monitor_golang/traffic_monitor/tools/nagios-validate-offline.go
----------------------------------------------------------------------
diff --git 
a/traffic_monitor_golang/traffic_monitor/tools/nagios-validate-offline.go 
b/traffic_monitor_golang/traffic_monitor/tools/nagios-validate-offline.go
index a54b8c5..ec2b9bd 100644
--- a/traffic_monitor_golang/traffic_monitor/tools/nagios-validate-offline.go
+++ b/traffic_monitor_golang/traffic_monitor/tools/nagios-validate-offline.go
@@ -1,3 +1,22 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you 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.
+ */
+
 package main
 
 import (

http://git-wip-us.apache.org/repos/asf/incubator-trafficcontrol/blob/2fdd9317/traffic_monitor_golang/traffic_monitor/tools/nagios-validate-peerpoller.go
----------------------------------------------------------------------
diff --git 
a/traffic_monitor_golang/traffic_monitor/tools/nagios-validate-peerpoller.go 
b/traffic_monitor_golang/traffic_monitor/tools/nagios-validate-peerpoller.go
index 5e9c9fd..6af1a51 100644
--- a/traffic_monitor_golang/traffic_monitor/tools/nagios-validate-peerpoller.go
+++ b/traffic_monitor_golang/traffic_monitor/tools/nagios-validate-peerpoller.go
@@ -1,3 +1,22 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you 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.
+ */
+
 package main
 
 import (
@@ -5,32 +24,46 @@ import (
        "fmt"
        
"github.com/apache/incubator-trafficcontrol/traffic_monitor_golang/common/nagios"
        
"github.com/apache/incubator-trafficcontrol/traffic_monitor_golang/traffic_monitor/tmcheck"
+       to "github.com/apache/incubator-trafficcontrol/traffic_ops/client"
 )
 
 const UserAgent = "tm-peerpoller-validator/0.1"
 
 func main() {
-       tmURI := flag.String("tm", "", "The Traffic Monitor URI, whose Peer 
Poller to validate")
-       // toUser := flag.String("touser", "", "The Traffic Ops user")
-       // toPass := flag.String("topass", "", "The Traffic Ops password")
-       // includeOffline := flag.Bool("includeOffline", false, "Whether to 
include Offline Monitors")
+       toURI := flag.String("to", "", "The Traffic Ops URI, whose CRConfig to 
validate")
+       toUser := flag.String("touser", "", "The Traffic Ops user")
+       toPass := flag.String("topass", "", "The Traffic Ops password")
+       includeOffline := flag.Bool("includeOffline", false, "Whether to 
include Offline Monitors")
        help := flag.Bool("help", false, "Usage info")
        helpBrief := flag.Bool("h", false, "Usage info")
        flag.Parse()
-       if *help || *helpBrief {
+       if *help || *helpBrief || *toURI == "" {
                fmt.Printf("Usage: ./nagios-validate-peerpoller -to 
https://traffic-ops.example.net -touser bill -topass thelizard -includeOffline 
true\n")
                return
        }
 
-       // toClient, err := to.LoginWithAgent(*toURI, *toUser, *toPass, true, 
UserAgent, false, tmcheck.RequestTimeout)
-       // if err != nil {
-       //      fmt.Printf("Error logging in to Traffic Ops: %v\n", err)
-       //      return
-       // }
+       toClient, err := to.LoginWithAgent(*toURI, *toUser, *toPass, true, 
UserAgent, false, tmcheck.RequestTimeout)
+       if err != nil {
+               fmt.Printf("Error logging in to Traffic Ops: %v\n", err)
+               return
+       }
+
+       monitorErrs, err := tmcheck.ValidateAllPeerPollers(toClient, 
*includeOffline)
 
-       err := tmcheck.ValidatePeerPoller(*tmURI)
        if err != nil {
-               nagios.Exit(nagios.Critical, fmt.Sprintf("Error validating 
monitor peer poller: %v", err))
+               nagios.Exit(nagios.Critical, fmt.Sprintf("Error validating 
monitor peer pollers: %v", err))
        }
+
+       errStr := ""
+       for monitor, err := range monitorErrs {
+               if err != nil {
+                       errStr += fmt.Sprintf("error validating offline status 
for monitor %v : %v\n", monitor, err.Error())
+               }
+       }
+
+       if errStr != "" {
+               nagios.Exit(nagios.Critical, errStr)
+       }
+
        nagios.Exit(nagios.Ok, "")
 }

Reply via email to