Function find_analyzers

Source
pub async fn find_analyzers(
    configuration: &Configuration,
    analyzer_find_request: Option<AnalyzerFindRequest>,
) -> Result<Vec<Worker>, Error<FindAnalyzersError>>
Examples found in repository?
examples/common.rs (line 56)
45pub async fn get_analyzer_id_by_name(
46    config: &Configuration,
47    analyzer_name_to_find: &str,
48) -> Result<Option<String>, Box<dyn std::error::Error>> {
49    println!(
50        "Fetching all analyzer instances to find ID for '{}'...",
51        analyzer_name_to_find
52    );
53
54    let find_request = Some(cortex_client::models::AnalyzerFindRequest::default());
55
56    match cortex_client::apis::analyzer_api::find_analyzers(config, find_request).await {
57        Ok(analyzer_instances) => {
58            // Directly a Vec<Worker>
59            for analyzer_instance in analyzer_instances {
60                if let Some(name) = &analyzer_instance.name {
61                    if name == analyzer_name_to_find {
62                        if let Some(id) = analyzer_instance._id {
63                            println!(
64                                "Found analyzer ID '{}' for name '{}'",
65                                id, analyzer_name_to_find
66                            );
67                            return Ok(Some(id));
68                        }
69                    }
70                }
71            }
72            println!("Analyzer with name '{}' not found.", analyzer_name_to_find);
73            Ok(None)
74        }
75        Err(e) => {
76            eprintln!("Error fetching analyzer instances: {:?}", e);
77            Err(Box::new(e))
78        }
79    }
80}
More examples
Hide additional examples
examples/list_analyzers.rs (line 62)
49async fn main() -> Result<(), Box<dyn std::error::Error>> {
50    let config = match common::setup_configuration() {
51        Ok(cfg) => cfg,
52        Err(e) => {
53            eprintln!("Configuration error: {}", e);
54            return Err(e.into());
55        }
56    };
57
58    println!("Fetching list of all analyzer instances...");
59
60    let find_request = Some(cortex_client::models::AnalyzerFindRequest::default());
61
62    match analyzer_api::find_analyzers(&config, find_request).await {
63        Ok(analyzers) => {
64            println!("\nSuccessfully fetched analyzer instances:");
65            if analyzers.is_empty() {
66                println!("No analyzer instances found in your Cortex organization.");
67            } else {
68                println!("--------------------------------------------------");
69                println!("Available Analyzer Instances:");
70                println!("--------------------------------------------------");
71                for worker_instance in &analyzers {
72                    // Iterate over the direct vector
73                    println!(
74                        "  Name:                 {}",
75                        worker_instance.name.as_deref().unwrap_or("N/A")
76                    );
77                    println!(
78                        "  Instance ID (_id):    {}", // THIS IS WHAT YOU NEED
79                        worker_instance._id.as_deref().unwrap_or("MISSING_ID")
80                    );
81                    println!(
82                        "  Definition ID:        {}",
83                        worker_instance
84                            .worker_definition_id
85                            .as_deref()
86                            .unwrap_or("N/A")
87                    );
88                    println!(
89                        "  Type:                 {:?}",
90                        worker_instance
91                            .r#type
92                            .unwrap_or(cortex_client::models::worker::Type::Analyzer) // Provide a default if None
93                    );
94                    println!("  Enabled (Implicitly): If listed, it's an instance. Check Cortex UI for explicit enabled/disabled status if unsure.");
95                    println!("  ---");
96                }
97                println!("\nTotal analyzer instances found: {}", analyzers.len());
98                println!("--------------------------------------------------");
99                println!("\nLook for your AbuseIPDB analyzer in the list above and use its 'Instance ID (_id)'");
100                println!(
101                    "in your abuseipdb_example.rs file for the 'analyzer_worker_id' variable."
102                );
103            }
104        }
105        Err(e) => {
106            eprintln!("\nError fetching analyzer instances: {:?}", e);
107            eprintln!("Please check your Cortex connection and API key permissions.");
108            if let cortex_client::apis::Error::Serde(serde_err) = e {
109                eprintln!("Serde error details: {}", serde_err);
110            }
111        }
112    }
113
114    Ok(())
115}