add resources command
parent
d597108609
commit
ae00e708da
|
@ -0,0 +1,9 @@
|
||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<module type="WEB_MODULE" version="4">
|
||||||
|
<component name="Go" enabled="true" />
|
||||||
|
<component name="NewModuleRootManager">
|
||||||
|
<content url="file://$MODULE_DIR$" />
|
||||||
|
<orderEntry type="inheritedJdk" />
|
||||||
|
<orderEntry type="sourceFolder" forTests="false" />
|
||||||
|
</component>
|
||||||
|
</module>
|
|
@ -0,0 +1,8 @@
|
||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<project version="4">
|
||||||
|
<component name="ProjectModuleManager">
|
||||||
|
<modules>
|
||||||
|
<module fileurl="file://$PROJECT_DIR$/.idea/CS-Control.iml" filepath="$PROJECT_DIR$/.idea/CS-Control.iml" />
|
||||||
|
</modules>
|
||||||
|
</component>
|
||||||
|
</project>
|
|
@ -0,0 +1,6 @@
|
||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<project version="4">
|
||||||
|
<component name="VcsDirectoryMappings">
|
||||||
|
<mapping directory="$PROJECT_DIR$" vcs="Git" />
|
||||||
|
</component>
|
||||||
|
</project>
|
|
@ -0,0 +1,42 @@
|
||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<project version="4">
|
||||||
|
<component name="ChangeListManager">
|
||||||
|
<list default="true" id="81638931-38b1-4ebe-9407-5f51f2b01d2a" name="Default Changelist" comment="">
|
||||||
|
<change beforePath="$PROJECT_DIR$/internal/custom.go" beforeDir="false" afterPath="$PROJECT_DIR$/internal/custom.go" afterDir="false" />
|
||||||
|
<change beforePath="$PROJECT_DIR$/internal/daemon.go" beforeDir="false" afterPath="$PROJECT_DIR$/internal/daemon.go" afterDir="false" />
|
||||||
|
<change beforePath="$PROJECT_DIR$/main.go" beforeDir="false" afterPath="$PROJECT_DIR$/main.go" afterDir="false" />
|
||||||
|
</list>
|
||||||
|
<option name="SHOW_DIALOG" value="false" />
|
||||||
|
<option name="HIGHLIGHT_CONFLICTS" value="true" />
|
||||||
|
<option name="HIGHLIGHT_NON_ACTIVE_CHANGELIST" value="false" />
|
||||||
|
<option name="LAST_RESOLUTION" value="IGNORE" />
|
||||||
|
</component>
|
||||||
|
<component name="GOROOT" url="file://$PROJECT_DIR$/../../../../Go" />
|
||||||
|
<component name="Git.Settings">
|
||||||
|
<option name="RECENT_GIT_ROOT_PATH" value="$PROJECT_DIR$" />
|
||||||
|
</component>
|
||||||
|
<component name="GoLibraries">
|
||||||
|
<option name="indexEntireGoPath" value="false" />
|
||||||
|
</component>
|
||||||
|
<component name="ProjectId" id="1mAPN2yrpYEo0Rd7piZqZFUHEUZ" />
|
||||||
|
<component name="ProjectViewState">
|
||||||
|
<option name="hideEmptyMiddlePackages" value="true" />
|
||||||
|
<option name="showLibraryContents" value="true" />
|
||||||
|
</component>
|
||||||
|
<component name="PropertiesComponent">
|
||||||
|
<property name="RunOnceActivity.OpenProjectViewOnStart" value="true" />
|
||||||
|
<property name="RunOnceActivity.ShowReadmeOnStart" value="true" />
|
||||||
|
<property name="WebServerToolWindowFactoryState" value="false" />
|
||||||
|
<property name="go.import.settings.migrated" value="true" />
|
||||||
|
<property name="go.sdk.automatically.set" value="true" />
|
||||||
|
<property name="go.tried.to.enable.integration.vgo.integrator" value="true" />
|
||||||
|
<property name="last_opened_file_path" value="$PROJECT_DIR$" />
|
||||||
|
</component>
|
||||||
|
<component name="SpellCheckerSettings" RuntimeDictionaries="0" Folders="0" CustomDictionaries="0" DefaultDictionary="application-level" UseSingleDictionary="true" transferred="true" />
|
||||||
|
<component name="TypeScriptGeneratedFilesManager">
|
||||||
|
<option name="version" value="3" />
|
||||||
|
</component>
|
||||||
|
<component name="VgoProject">
|
||||||
|
<integration-enabled>true</integration-enabled>
|
||||||
|
</component>
|
||||||
|
</project>
|
|
@ -0,0 +1,38 @@
|
||||||
|
package cmd
|
||||||
|
|
||||||
|
import (
|
||||||
|
"fmt"
|
||||||
|
"github.com/olekukonko/tablewriter"
|
||||||
|
"github.com/urfave/cli/v2"
|
||||||
|
"os/user"
|
||||||
|
"strings"
|
||||||
|
|
||||||
|
"csctl/internal"
|
||||||
|
)
|
||||||
|
|
||||||
|
func Resources(*cli.Context) error {
|
||||||
|
u, _ := user.Current()
|
||||||
|
|
||||||
|
memoryUsage, err := internal.ContactSR(&internal.TCPData{Type: "mem", Username: u.Username})
|
||||||
|
if err != nil {
|
||||||
|
return internal.Error(err, "Unable to fetch information from CSD.")
|
||||||
|
}
|
||||||
|
storageUsage, err := internal.ContactSR(&internal.TCPData{Type: "storage", Username: u.Username})
|
||||||
|
if err != nil {
|
||||||
|
return internal.Error(err, "Unable to fetch information from CSD.")
|
||||||
|
}
|
||||||
|
processCount, err := internal.ContactSR(&internal.TCPData{Type: "processcount", Username: u.Username})
|
||||||
|
if err != nil {
|
||||||
|
return internal.Error(err, "Unable to fetch information from CSD.")
|
||||||
|
}
|
||||||
|
sshLogins, err := internal.ContactSR(&internal.TCPData{Type: "sshlogins", Username: u.Username})
|
||||||
|
|
||||||
|
tableString := &strings.Builder{}
|
||||||
|
table := tablewriter.NewWriter(tableString)
|
||||||
|
table.SetHeader([]string{"RAM Usage", "Storage Usage", "Processes Running", "SSH Logins"})
|
||||||
|
table.Append([]string{memoryUsage, storageUsage, processCount, sshLogins})
|
||||||
|
table.Render()
|
||||||
|
|
||||||
|
fmt.Println(tableString.String())
|
||||||
|
return nil
|
||||||
|
}
|
|
@ -1,6 +1,7 @@
|
||||||
package internal
|
package internal
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"errors"
|
||||||
"fmt"
|
"fmt"
|
||||||
"github.com/kataras/golog"
|
"github.com/kataras/golog"
|
||||||
"os"
|
"os"
|
||||||
|
@ -8,7 +9,7 @@ import (
|
||||||
"time"
|
"time"
|
||||||
)
|
)
|
||||||
|
|
||||||
func Error(err error, msg string) {
|
func Error(err error, msg string) error {
|
||||||
currentUser, _ := user.Current()
|
currentUser, _ := user.Current()
|
||||||
path := fmt.Sprintf("%s/.csctl.err.log", currentUser.HomeDir)
|
path := fmt.Sprintf("%s/.csctl.err.log", currentUser.HomeDir)
|
||||||
file, errf := os.OpenFile(path, os.O_WRONLY|os.O_APPEND|os.O_CREATE, 0600)
|
file, errf := os.OpenFile(path, os.O_WRONLY|os.O_APPEND|os.O_CREATE, 0600)
|
||||||
|
@ -26,4 +27,5 @@ func Error(err error, msg string) {
|
||||||
panic(errf)
|
panic(errf)
|
||||||
}
|
}
|
||||||
golog.Fatal("An error has occurred while processing the executable. A log file has been created in %s, please alert a Technician and provide the contents of this file if needed.\n", path)
|
golog.Fatal("An error has occurred while processing the executable. A log file has been created in %s, please alert a Technician and provide the contents of this file if needed.\n", path)
|
||||||
|
return errors.New(fmt.Sprintf("%s\n\nError Details: %s", msg, err))
|
||||||
}
|
}
|
||||||
|
|
|
@ -45,8 +45,7 @@ func FetchAccount(username string) (*Account, error) {
|
||||||
}
|
}
|
||||||
|
|
||||||
var account Account
|
var account Account
|
||||||
err = json.Unmarshal([]byte(data), &account)
|
if err := json.Unmarshal([]byte(data), &account); err != nil {
|
||||||
if err != nil {
|
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
return &account, nil
|
return &account, nil
|
||||||
|
|
Loading…
Reference in New Issue