]> git.nbdom.net Git - nb.git/commitdiff
etc/profile.d/sys.sh
authorNicolas Boisselier <nicolas.boisselier@gmail.com>
Sat, 4 Feb 2017 22:51:32 +0000 (22:51 +0000)
committerNicolas Boisselier <nicolas.boisselier@gmail.com>
Sat, 4 Feb 2017 22:51:32 +0000 (22:51 +0000)
bin/ovh-api
etc/profile.d/sys.sh

index febf94bbf48a755a1048614070c8d45fd0c5c835..92b46f73661a23145b83aa0d28cddf71918cb6da 100755 (executable)
@@ -118,7 +118,8 @@ sub query {
     print "[\n" if @$content>0;
     my $count = 0;
     for my $id (@$content) {
-      next if $URL eq '/ip' and $id !~ /\d+\./;
+      $id = check_row($URL,$id);
+      next unless defined $id;
 
       $id =~ s,/.*$,,;
       $response = $Api->rawCall(path=>$URL.'/'.$id,method=>$Opt{method},body=>{});
@@ -138,6 +139,32 @@ sub query {
        print "$content\n";
 }
 
+sub sql {
+my $pref = 'ovh_';
+my @tables = (
+  {
+    name => 'ip',
+    url => '/ip',
+    sql => 'CREATE TABLE IF NOT EXISTS '.$pref.'ip ('
+    .');',
+  },
+  {
+    name => 'server',
+    url => '/server',
+    sql => 'CREATE TABLE IF NOT EXISTS '.$pref.'server ('
+      .'serverid INT,'
+    .');',
+  },
+);
+}
+
+sub check_row {
+  my ($URL,$id) = @_;
+  return undef if $URL eq '/ip' and $id !~ /\d+\./;
+  $id =~ s,/.*$,,;
+  return $id;
+}
+
 sub help {
 #------------------------------------------------------------------------------
 # Print help and exit
@@ -234,6 +261,7 @@ $NAME - Script to query ovh's api
   4. Use the api
     $NAME applicationKey:applicationSecret:consumerKey /PATH
     $NAME /PATH
+    $NAME --rows /PATH
 
 =head1 OPTIONS
 
index 647a51cb834f9123151549d08552e2196c4a8ebc..43b8e8a62b2c708e1785cce2409e219243266f40 100644 (file)
@@ -11,6 +11,7 @@ sys_watch() {
   local opt="$@"
   [ -z "$opt" ] && opt="-d"
 
+  export -f sys_activity
   watch --no-title $opt bash -c "sys_activity"
 }