1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
use crate::error::{MetricsResult, StorageError};
use crate::ir::{TsPoint, TsValue};
use crate::IntoPoint;
use chrono::offset::Utc;
use chrono::DateTime;
use log::{error, trace};
use reqwest::header::{HeaderMap, HeaderValue, ACCEPT};
use serde::de::DeserializeOwned;
/**
* Copyright 2019 Comcast Cable Communications Management, LLC
*
* 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.
*
* SPDX-License-Identifier: Apache-2.0
*/
use std::fmt::Debug;

#[derive(Clone, Deserialize, Debug)]
pub struct BrocadeConfig {
    /// The brocade endpoint to use
    pub endpoint: String,
    pub user: String,
    /// This gets replaced with the token at runtime
    pub password: String,
    /// Optional certificate file to use against the server
    /// der encoded
    pub certificate: Option<String>,
    /// Optional root certificate file to use against the server
    /// der encoded
    pub root_certificate: Option<String>,
    /// The region this cluster is located in
    pub region: String,
}

pub struct Brocade {
    client: reqwest::Client,
    config: BrocadeConfig,
    token: String,
}

impl Brocade {
    /// Initialize and connect to a Brocade switch.
    pub fn new(client: &reqwest::Client, config: BrocadeConfig) -> MetricsResult<Self> {
        let token = login(&client, &config)?;
        Ok(Brocade {
            client: client.clone(),
            config,
            token,
        })
    }
}

impl Drop for Brocade {
    fn drop(&mut self) {
        if let Err(e) = self.logout() {
            error!("logout failed: {}", e);
        }
    }
}

#[test]
fn parse_resource_groups() {
    use std::fs::File;
    use std::io::Read;

    let mut f = File::open("tests/brocade/resource_groups.json").unwrap();
    let mut buff = String::new();
    f.read_to_string(&mut buff).unwrap();

    let i: ResourceGroups = serde_json::from_str(&buff).unwrap();
    println!("result: {:#?}", i);
}
#[serde(rename_all = "camelCase")]
#[derive(Deserialize, Debug)]
pub struct ResourceGroups {
    pub resource_groups: Vec<ResourceGroup>,
}

#[derive(Deserialize, Debug)]
pub struct ResourceGroup {
    pub key: String,
    pub name: String,
    #[serde(rename = "type")]
    pub resource_type: String,
}

#[serde(rename_all = "camelCase")]
#[derive(Deserialize, Debug)]
pub struct BufferCredit {
    pub bb_credit: u64,
    #[serde(rename = "peerBBCredit")]
    pub peer_bb_credit: u64,
    pub round_trip_time: u64,
}

#[test]
fn parse_fc_fabrics() {
    use std::fs::File;
    use std::io::Read;

    let mut f = File::open("tests/brocade/fcfabrics.json").unwrap();
    let mut buff = String::new();
    f.read_to_string(&mut buff).unwrap();

    let i: FcFabrics = serde_json::from_str(&buff).unwrap();
    println!("result: {:#?}", i);
}

#[serde(rename_all = "camelCase")]
#[derive(Deserialize, Debug)]
pub struct FcFabrics {
    pub fc_fabrics: Vec<FcFabric>,
    pub start_index: Option<i32>,
    pub items_per_page: Option<i32>,
    pub total_results: Option<u64>,
}

#[serde(rename_all = "camelCase")]
#[derive(Deserialize, Debug, IntoPoint)]
pub struct FcFabric {
    pub key: String,
    pub seed_switch_wwn: String,
    pub name: String,
    pub secure: bool,
    pub ad_environment: bool,
    pub contact: Option<String>,
    pub location: Option<String>,
    pub description: Option<String>,
    pub principal_switch_wwn: String,
    pub fabric_name: String,
    pub virtual_fabric_id: i32,
    pub seed_switch_ip_address: String,
}

#[serde(rename_all = "camelCase")]
#[derive(Deserialize, Debug)]
pub struct FcPorts {
    pub fc_ports: Vec<FcPort>,
    pub start_index: Option<i32>,
    pub items_per_page: Option<i32>,
    pub total_results: Option<u64>,
}

#[test]
fn parse_fc_ports() {
    use std::fs::File;
    use std::io::Read;

    let mut f = File::open("tests/brocade/fcports.json").unwrap();
    let mut buff = String::new();
    f.read_to_string(&mut buff).unwrap();

    let i: FcPorts = serde_json::from_str(&buff).unwrap();
    println!("result: {:#?}", i);
}

#[serde(rename_all = "camelCase")]
#[derive(Deserialize, Debug, IntoPoint)]
pub struct FcPort {
    key: String,
    wwn: String,
    name: String,
    slot_number: u64,
    port_number: u64,
    user_port_number: u64,
    port_id: String,
    port_index: u64,
    area_id: u64,
    #[serde(rename = "type")]
    port_type: String,
    status: String,
    status_message: String,
    locked_port_type: String,
    speed: String,
    speeds_supported: String,
    max_port_speed: u16,
    desired_credits: u64,
    buffer_allocated: u64,
    estimated_distance: u64,
    actual_distance: u64,
    long_distance_setting: u64,
    remote_node_wwn: String,
    remote_port_wwn: String,
    licensed: bool,
    swapped: bool,
    trunked: bool,
    trunk_master: bool,
    persistently_disabled: bool,
    ficon_supported: bool,
    blocked: bool,
    prohibit_port_numbers: Option<String>,
    prohibit_port_count: u64,
    npiv_capable: bool,
    npiv_enabled: bool,
    fc_fast_write_enabled: bool,
    isl_rrdy_enabled: bool,
    rate_limit_capable: bool,
    rate_limited: bool,
    qos_capable: bool,
    qos_enabled: bool,
    fcr_fabric_id: u64,
    state: String,
    occupied: bool,
    master_port_number: i64,
}

#[serde(rename_all = "camelCase")]
#[derive(Deserialize, Debug)]
pub struct Fec {
    pub corrected_blocks: u64,
    pub uncorrected_blocks: u64,
}

#[test]
fn parse_fc_switches() {
    use std::fs::File;
    use std::io::Read;

    let mut f = File::open("tests/brocade/fcswitches.json").unwrap();
    let mut buff = String::new();
    f.read_to_string(&mut buff).unwrap();

    let i: FcSwitches = serde_json::from_str(&buff).unwrap();
    println!("result: {:#?}", i);
}

#[serde(rename_all = "camelCase")]
#[derive(Deserialize, Debug)]
pub struct FcSwitches {
    pub fc_switches: Vec<FcSwitch>,
    pub start_index: Option<i32>,
    pub items_per_page: Option<i32>,
    pub total_results: Option<u64>,
}

#[serde(rename_all = "camelCase")]
#[derive(Deserialize, Debug, IntoPoint)]
pub struct FcSwitch {
    pub key: String,
    #[serde(rename = "type")]
    pub fc_type: u64,
    pub name: String,
    pub wwn: String,
    pub virtual_fabric_id: i64,
    pub domain_id: u64,
    pub base_switch: bool,
    pub role: String,
    pub fcs_role: String,
    pub ad_capable: bool,
    pub operational_status: String,
    pub state: String,
    pub status_reason: Option<String>,
    pub lf_enabled: bool,
    pub default_logical_switch: bool,
    pub fms_mode: bool,
    pub dynamic_load_sharing_capable: bool,
    pub port_based_routing_present: bool,
    pub in_order_delivery_capable: bool,
    pub persistent_did_enabled: bool,
    pub auto_snmp_enabled: bool,
}

pub enum FabricTimeSeries {
    MemoryUtilPercentage,
    CpuUtilPercentage,
    Temperature,
    FanSpeed,
    ResponseTime,
    SystemUpTime,
    PortsNotInUse,
    PingPktLossPercentage,
}

impl ToString for FabricTimeSeries {
    fn to_string(&self) -> String {
        match *self {
            FabricTimeSeries::MemoryUtilPercentage => "timeseriesmemoryutilpercentage".into(),
            FabricTimeSeries::CpuUtilPercentage => "timeseriescpuutilpercentage".into(),
            FabricTimeSeries::Temperature => "timeseriestemperature".into(),
            FabricTimeSeries::FanSpeed => "timeseriesfanspeed".into(),
            FabricTimeSeries::ResponseTime => "timeseriesresponsetime".into(),
            FabricTimeSeries::SystemUpTime => "timeseriessystemuptime".into(),
            FabricTimeSeries::PortsNotInUse => "timeseriesportsnotinuse".into(),
            FabricTimeSeries::PingPktLossPercentage => "timeseriespingpktlosspercentage".into(),
        }
    }
}

pub enum FcIpTimeSeries {
    CompressionRatio,
    Latency,
    DroppedPackets,
    LinkRetransmits,
    TimeoutRetransmits,
    FastRetransmits,
    DupAckRecvd,
    WindowSizeRtt,
    TcpOooSegments,
    SlowStartStatusErrors,
    RealtimeCompressionRatio,
}

impl ToString for FcIpTimeSeries {
    fn to_string(&self) -> String {
        match *self {
            FcIpTimeSeries::CompressionRatio => "timeseriescompressionratio".into(),
            FcIpTimeSeries::Latency => "timeserieslatency".into(),
            FcIpTimeSeries::DroppedPackets => "timeseriesdroppedpackets".into(),
            FcIpTimeSeries::LinkRetransmits => "timeserieslinkretransmits".into(),
            FcIpTimeSeries::TimeoutRetransmits => "timeseriestimeoutretransmits".into(),
            FcIpTimeSeries::FastRetransmits => "timeseriesfastretransmits".into(),
            FcIpTimeSeries::DupAckRecvd => "timeseriesdupackrecvd".into(),
            FcIpTimeSeries::WindowSizeRtt => "timeserieswindowsizertt".into(),
            FcIpTimeSeries::TcpOooSegments => "timeseriestcpooosegments".into(),
            FcIpTimeSeries::SlowStartStatusErrors => "timeseriesslowstartstatuserrors".into(),
            FcIpTimeSeries::RealtimeCompressionRatio => "timeseriesrealtimecompressionratio".into(),
        }
    }
}
pub enum FcTimeSeries {
    UtilPercentage,
    Traffic,
    CrcErrors,
    LinkResets,
    SignalLosses,
    SyncLosses,
    LinkFailures,
    SequenceErrors,
    InvalidTransmissions,
    C3Discards,
    C3DiscardsTxTo,
    C3DiscardsRxTo,
    C3DiscardsUnreachable,
    C3DiscardsOther,
    EncodeErrorOut,
    SfpPower,
    SfpVoltage,
    SfpCurrent,
    SfpTemperature,
    InvalidOrderedSets,
    BbCreditZero,
    TruncatedFrames,
}

impl ToString for FcTimeSeries {
    fn to_string(&self) -> String {
        match *self {
            FcTimeSeries::UtilPercentage => "timeseriesutilpercentage".into(),
            FcTimeSeries::Traffic => "timeseriestraffic".into(),
            FcTimeSeries::CrcErrors => "timeseriescrcerrors".into(),
            FcTimeSeries::LinkResets => "timeserieslinkresets".into(),
            FcTimeSeries::SignalLosses => "timeseriessignallosses".into(),
            FcTimeSeries::SyncLosses => "timeseriessynclosses".into(),
            FcTimeSeries::LinkFailures => "timeserieslinkfailures".into(),
            FcTimeSeries::SequenceErrors => "timeseriessequenceerrors".into(),
            FcTimeSeries::InvalidTransmissions => "timeseriesinvalidtransmissions".into(),
            FcTimeSeries::C3Discards => "timeseriesc3discards".into(),
            FcTimeSeries::C3DiscardsTxTo => "timeseriesc3discardstxto".into(),
            FcTimeSeries::C3DiscardsRxTo => "timeseriesc3discardsrxto".into(),
            FcTimeSeries::C3DiscardsUnreachable => "timeseriesc3discardsunreachable".into(),
            FcTimeSeries::C3DiscardsOther => "timeseriesc3discardsother".into(),
            FcTimeSeries::EncodeErrorOut => "timeseriesencodeerrorout".into(),
            FcTimeSeries::SfpPower => "timeseriessfppower".into(),
            FcTimeSeries::SfpVoltage => "timeseriessfpvoltage".into(),
            FcTimeSeries::SfpCurrent => "timeseriessfpcurrent".into(),
            FcTimeSeries::SfpTemperature => "timeseriessfptemperature".into(),
            FcTimeSeries::InvalidOrderedSets => "timeseriesinvalidorderedsets".into(),
            FcTimeSeries::BbCreditZero => "timeseriesbbcreditzero".into(),
            FcTimeSeries::TruncatedFrames => "timeseriestruncatedframes".into(),
        }
    }
}

pub enum FrameTimeSeries {
    TxFrameCount,
    RxFrameCount,
    TxFrameRate,
    RxFrameRate,
    TxWordCount,
    RxWordCount,
    TxThroughput,
    RxThroughput,
    AvgTxFrameSize,
    AvgRxFrameSize,
    GeneratorTxFrameCount,
    GeneratorRxFrameCount,
    MirroredFramesCount,
    MirroredTxFrames,
    MirroredRxFrames,
}

impl ToString for FrameTimeSeries {
    fn to_string(&self) -> String {
        match *self {
            FrameTimeSeries::TxFrameCount => "timeseriestxframecount".into(),
            FrameTimeSeries::RxFrameCount => "timeseriesrxframecount".into(),
            FrameTimeSeries::TxFrameRate => "timeseriestxframerate".into(),
            FrameTimeSeries::RxFrameRate => "timeseriesrxframerate".into(),
            FrameTimeSeries::TxWordCount => "timeseriestxwordcount".into(),
            FrameTimeSeries::RxWordCount => "timeseriesrxwordcount".into(),
            FrameTimeSeries::TxThroughput => "timeseriestxthroughput".into(),
            FrameTimeSeries::RxThroughput => "timeseriesrxthroughput".into(),
            FrameTimeSeries::AvgTxFrameSize => "timeseriesavgtxframesize".into(),
            FrameTimeSeries::AvgRxFrameSize => "timeseriesavgrxframesize".into(),
            FrameTimeSeries::GeneratorTxFrameCount => "timeseriesgeneratortxframecount".into(),
            FrameTimeSeries::GeneratorRxFrameCount => "timeseriesgeneratorrxframecount".into(),
            FrameTimeSeries::MirroredFramesCount => "timeseriesmirroredframescount".into(),
            FrameTimeSeries::MirroredTxFrames => "timeseriesmirroredtxframes".into(),
            FrameTimeSeries::MirroredRxFrames => "timeseriesmirroredrxframes".into(),
        }
    }
}

pub struct ReadDiagnostic {
    pub switch_name: String,
    pub switch_wwn: String,
    pub number_of_ports: u64,
    pub stats_type: RdpStatsType,
    pub port_wwn: String,
    pub port_type: String,
    pub node_wwn: String,
    pub tx_power: String,
    pub rx_power: String,
    pub temperature: String,
    pub sfp_type: String,
    pub laser_type: String,
    pub voltage: String,
    pub current: String,
    pub connecter_type: String,
    pub supported_speeds: String,
    pub link_failure: u64,
    pub loss_of_sync: u64,
    pub loss_of_signal: u64,
    pub protocol_error: u64,
    pub invalid_word: u64,
    pub invalid_crc: u64,
    pub fec: Fec,
    pub buffer_credit: BufferCredit,
}

pub enum RdpStatsType {
    Historical,
    Realtime,
}

pub enum ScsiTimeSeries {
    ReadFrameCount,
    WriteFrameCount,
    ReadFrameRate,
    WriteFrameRate,
    ReadData,
    WriteData,
    ReadDataRate,
    WriteDataRate,
}

impl ToString for ScsiTimeSeries {
    fn to_string(&self) -> String {
        match *self {
            ScsiTimeSeries::ReadFrameCount => "timeseriesscsireadframecount".into(),
            ScsiTimeSeries::WriteFrameCount => "timeseriesscsiwriteframecount".into(),
            ScsiTimeSeries::ReadFrameRate => "timeseriesscsireadframerate".into(),
            ScsiTimeSeries::WriteFrameRate => "timeseriesscsiwriteframerate".into(),
            ScsiTimeSeries::ReadData => "timeseriesscsireaddata".into(),
            ScsiTimeSeries::WriteData => "timeseriesscsiwritedata".into(),
            ScsiTimeSeries::ReadDataRate => "timeseriesscsireaddatarate".into(),
            ScsiTimeSeries::WriteDataRate => "timeseriesscsiwritedatarate".into(),
        }
    }
}

pub enum TimeSeries {
    Fc(FcTimeSeries),
    FcIp(FcIpTimeSeries),
}

// Connect to the server and request a new api token
pub fn login(client: &reqwest::Client, config: &BrocadeConfig) -> MetricsResult<String> {
    let mut headers = HeaderMap::new();
    headers.insert(
        ACCEPT,
        HeaderValue::from_str("application/vnd.brocade.networkadvisor+json;version=v1")?,
    );
    headers.insert("WSUsername", HeaderValue::from_str(&config.user)?);
    headers.insert("WSPassword", HeaderValue::from_str(&config.password)?);

    let resp = client
        .post(&format!(
            "{}://{}/rest/login",
            match config.certificate {
                Some(_) => "https",
                None => "http",
            },
            config.endpoint
        ))
        .headers(headers)
        .send()?
        .error_for_status()?;

    // We need a WSToken back from the server which takes the place of the
    // password in future requests
    let token = resp.headers().get("WStoken");
    match token {
        Some(data) => Ok(data.to_str()?.to_owned()),
        None => Err(StorageError::new(format!(
            "WSToken multiple lines. {:?}. Please check server",
            token
        ))),
    }
}

impl Brocade {
    // Deletes the client session
    pub fn logout(&self) -> MetricsResult<()> {
        let mut headers = HeaderMap::new();
        headers.insert("WStoken", HeaderValue::from_str(&self.token)?);

        self.client
            .post(&format!(
                "{}://{}/rest/logout",
                match self.config.certificate {
                    Some(_) => "https",
                    None => "http",
                },
                self.config.endpoint
            ))
            .headers(headers)
            .send()?
            .error_for_status()?;
        Ok(())
    }

    fn get_server_response<T>(&self, api_call: &str, ws_token: &str) -> MetricsResult<T>
    where
        T: DeserializeOwned + Debug,
    {
        let url = format!(
            "{}://{}/rest/{}",
            match self.config.certificate {
                Some(_) => "https",
                None => "http",
            },
            self.config.endpoint,
            api_call
        );
        let resp = self
            .client
            .get(&url)
            .header(
                ACCEPT,
                "application/vnd.brocade.networkadvisor+json;version=v1",
            )
            .header("WStoken", HeaderValue::from_str(&ws_token)?)
            .send()?
            .error_for_status()?
            .text()?;
        trace!("server returned: {}", resp);
        let json: Result<T, serde_json::Error> = serde_json::from_str(&resp);
        trace!("json result: {:?}", json);
        Ok(json?)
    }

    pub fn get_fc_fabrics(&self, t: DateTime<Utc>) -> MetricsResult<Vec<TsPoint>> {
        let result =
            self.get_server_response::<FcFabrics>("resourcegroups/All/fcfabrics", &self.token)?;
        let mut points = result
            .fc_fabrics
            .iter()
            .flat_map(|fabric| fabric.into_point(Some("brocade_fc_fabric"), true))
            .collect::<Vec<TsPoint>>();
        for point in &mut points {
            point.timestamp = Some(t)
        }
        Ok(points)
    }

    pub fn get_fc_switch_timeseries(
        &self,
        switch_key: &str,
        timeseries: TimeSeries,
    ) -> MetricsResult<()> {
        // TODO: Not sure if these performance metrics need to be enabled on the switches first
        let _url = format!(
            "resourcegroups/All/fcswitches/{}/{}?duration=360",
            switch_key,
            match timeseries {
                TimeSeries::Fc(ts) => ts.to_string(),
                TimeSeries::FcIp(ts) => ts.to_string(),
            }
        );
        Ok(())
    }

    pub fn get_fc_fabric_timeseries(
        &self,
        fabric_key: &str,
        timeseries: &FabricTimeSeries,
    ) -> MetricsResult<()> {
        // TODO: Not sure if these performance metrics need to be enabled on the switches first
        let _url = format!(
            "resourcegroups/All/fcfabrics/{}/{}?duration=360",
            fabric_key,
            timeseries.to_string(),
        );

        Ok(())
    }

    pub fn get_fc_fabric_ids(&self) -> MetricsResult<Vec<String>> {
        let result = self
            .get_server_response::<FcFabrics>("resourcegroups/All/fcfabrics", &self.token)
            .and_then(|fabrics| {
                let fabrics: Vec<String> = fabrics
                    .fc_fabrics
                    .iter()
                    .map(|fabric| fabric.key.clone())
                    .collect::<Vec<String>>();
                Ok(fabrics)
            })?;
        Ok(result)
    }

    pub fn get_fc_ports(&self, fabric_key: &str, t: DateTime<Utc>) -> MetricsResult<Vec<TsPoint>> {
        let result = self.get_server_response::<FcPorts>(
            &format!("resourcegroups/All/fcswitches/{}/fcports", fabric_key),
            &self.token,
        )?;
        let mut points = result
            .fc_ports
            .iter()
            .flat_map(|port| port.into_point(Some("brocade_fc_port"), true))
            .collect::<Vec<TsPoint>>();
        for point in &mut points {
            point.timestamp = Some(t)
        }
        Ok(points)
    }

    pub fn get_fc_switch_ids(&self) -> MetricsResult<Vec<String>> {
        let result = self
            .get_server_response::<FcSwitches>("resourcegroups/All/fcswitches", &self.token)
            .and_then(|switches| {
                let switches: Vec<String> = switches
                    .fc_switches
                    .iter()
                    .map(|switch| switch.key.clone())
                    .collect::<Vec<String>>();
                Ok(switches)
            })?;
        Ok(result)
    }

    pub fn get_fc_switches(&self, t: DateTime<Utc>) -> MetricsResult<Vec<TsPoint>> {
        let result =
            self.get_server_response::<FcSwitches>("resourcegroups/All/fcswitches", &self.token)?;
        let mut points = result
            .fc_switches
            .iter()
            .flat_map(|switch| switch.into_point(Some("brocade_fc_switch"), true))
            .collect::<Vec<TsPoint>>();
        for point in &mut points {
            point.timestamp = Some(t)
        }
        Ok(points)
    }

    pub fn get_resource_groups(&self) -> MetricsResult<ResourceGroups> {
        let result = self.get_server_response::<ResourceGroups>("resourcegroups", &self.token)?;
        Ok(result)
    }
}