Exemple #1
0
func ListAllPlugins(repoUrl string) (m.PluginRepo, error) {
	body, err := createRequest(repoUrl, "repo")

	if err != nil {
		logger.Info("Failed to create request", "error", err)
		return m.PluginRepo{}, fmt.Errorf("Failed to create request. error: %v", err)
	}

	if err != nil {
		return m.PluginRepo{}, err
	}

	var data m.PluginRepo
	err = json.Unmarshal(body, &data)
	if err != nil {
		logger.Info("Failed to unmarshal graphite response error: %v", err)
		return m.PluginRepo{}, err
	}

	return data, nil
}
Exemple #2
0
func GetPlugin(pluginId, repoUrl string) (m.Plugin, error) {
	body, err := sendRequest(repoUrl, "repo", pluginId)

	if err != nil {
		logger.Info("Failed to send request", "error", err)
		return m.Plugin{}, fmt.Errorf("Failed to send request. error: %v", err)
	}

	if err != nil {
		return m.Plugin{}, err
	}

	var data m.Plugin
	err = json.Unmarshal(body, &data)
	if err != nil {
		logger.Info("Failed to unmarshal graphite response error: %v", err)
		return m.Plugin{}, err
	}

	return data, nil
}
Exemple #3
0
func runCommand(command func(commandLine CommandLine) error) func(context *cli.Context) {
	return func(context *cli.Context) {

		cmd := &contextCommandLine{context}
		if err := command(cmd); err != nil {
			logger.Errorf("\n%s: ", color.RedString("Error"))
			logger.Errorf("%s\n\n", err)

			cmd.ShowHelp()
			os.Exit(1)
		} else {
			logger.Info("\nRestart grafana after installing plugins . <service grafana-server restart>\n\n")
		}
	}
}
Exemple #4
0
func lsCommand(c CommandLine) error {
	pluginDir := c.GlobalString("pluginsDir")
	if err := validateLsCommand(pluginDir); err != nil {
		return err
	}

	plugins := ls_getPlugins(pluginDir)

	if len(plugins) > 0 {
		logger.Info("installed plugins:\n")
	}

	for _, plugin := range plugins {
		logger.Infof("%s %s %s \n", plugin.Id, color.YellowString("@"), plugin.Info.Version)
	}

	return nil
}
Exemple #5
0
func InstallPlugin(pluginName, version string, c CommandLine) error {
	plugin, err := s.GetPlugin(pluginName, c.GlobalString("repo"))
	pluginFolder := c.GlobalString("pluginsDir")
	if err != nil {
		return err
	}

	v, err := SelectVersion(plugin, version)
	if err != nil {
		return err
	}

	if version == "" {
		version = v.Version
	}

	downloadURL := fmt.Sprintf("%s/%s/versions/%s/download",
		c.GlobalString("repo"),
		pluginName,
		version)

	logger.Infof("installing %v @ %v\n", plugin.Id, version)
	logger.Infof("from url: %v\n", downloadURL)
	logger.Infof("into: %v\n", pluginFolder)
	logger.Info("\n")

	err = downloadFile(plugin.Id, pluginFolder, downloadURL)
	if err != nil {
		return err
	}

	logger.Infof("%s Installed %s successfully \n", color.GreenString("✔"), plugin.Id)

	/* Enable once we need support for downloading depedencies
	res, _ := s.ReadPlugin(pluginFolder, pluginName)
	for _, v := range res.Dependency.Plugins {
		InstallPlugin(v.Id, version, c)
		log.Infof("Installed dependency: %v ✔\n", v.Id)
	}
	*/
	return err
}
Exemple #6
0
func runDbCommand(command func(commandLine CommandLine) error) func(context *cli.Context) {
	return func(context *cli.Context) {

		flag.Parse()
		setting.NewConfigContext(&setting.CommandLineArgs{
			Config:   *configFile,
			HomePath: *homePath,
			Args:     flag.Args(),
		})

		sqlstore.NewEngine()

		cmd := &contextCommandLine{context}
		if err := command(cmd); err != nil {
			logger.Errorf("\n%s: ", color.RedString("Error"))
			logger.Errorf("%s\n\n", err)

			cmd.ShowHelp()
			os.Exit(1)
		} else {
			logger.Info("\n\n")
		}
	}
}